library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub yuruhi/library

:heavy_check_mark: math/EnumeratePrimes.cpp

Depends on

Verified with

Code

#pragma once
#include "./Eratosthenes.cpp"
#include <vector>

std::vector<int> EnumeratePrimes(std::size_t n) {
	std::vector<int> result;
	auto p = Eratosthenes(n);
	for (std::size_t i = 2; i <= n; ++i) {
		if (p[i]) result.push_back(i);
	}
	return result;
}
#line 2 "math/Eratosthenes.cpp"
#include <vector>

std::vector<bool> Eratosthenes(size_t n) {
	std::vector<bool> result(n + 1, true);
	result[0] = result[1] = false;
	for (size_t i = 2; i * i <= n; ++i) {
		if (result[i]) {
			for (size_t j = i * i; j <= n; j += i) result[j] = false;
		}
	}
	return result;
}
#line 4 "math/EnumeratePrimes.cpp"

std::vector<int> EnumeratePrimes(std::size_t n) {
	std::vector<int> result;
	auto p = Eratosthenes(n);
	for (std::size_t i = 2; i <= n; ++i) {
		if (p[i]) result.push_back(i);
	}
	return result;
}
Back to top page