AlgoPlus v0.1.0
Loading...
Searching...
No Matches
eratosthenes_sieve.h
1#ifndef ERATOSTHENES_SIEVE_H
2#define ERATOSTHENES_SIEVE_H
3
4#ifdef __cplusplus
5#include <assert.h>
6#include <iostream>
7#include <vector>
8#endif
9
16std::vector<bool> soe(int64_t n) {
17 assert(n != 0);
18 std::vector<bool> prime(n + 1, true);
19 for (int64_t p = 2; p * p <= n; ++p) {
20 if (prime[p]) {
21 for (int64_t i = p * p; i <= n; i += p) {
22 prime[i] = false;
23 }
24 }
25 }
26 return prime;
27}
28
29#endif