-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrivo.cpp
More file actions
36 lines (29 loc) · 873 Bytes
/
crivo.cpp
File metadata and controls
36 lines (29 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 10000010; // 10^7 should be enough for most cases
bitset<NMAX> bs;
vector<int> p; // vector p of primes
void crivo(long long n){ // create list of primes in [0..n]
long long lim = n + 1; // add 1 to include n
bs.set(); // set all bits to 1
bs[0] = bs[1] = 0; // except index 0 and 1
for(long long i = 2; i <= lim; i++){
if(bs[i]){
for(long long j = i * i; j <= lim; j += i){ // cross out multiples of i starting from i * i!
bs[j] = 0;
}
p.push_back((int)i); // also add this vector containing list of primes
}
}
}
int main()
{
crivo(100);
if(bs[7]){
puts("ok");
}
else{
puts("nok");
}
return 0;
}