-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem07.cpp
More file actions
47 lines (41 loc) · 757 Bytes
/
Copy pathProblem07.cpp
File metadata and controls
47 lines (41 loc) · 757 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
37
38
39
40
41
42
43
44
45
46
47
/*
Krishna Mohan
Project Euler - Problem 7
Date: 3/15/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int (i)=0;(i)<(n); (i)++)
#define MAX 10000001
bitset<MAX> isPrime;
vector<int> primes;
void init()
{
isPrime.set();
isPrime[0]=isPrime[1]=0;
int sq=sqrt(MAX);
primes.push_back(2);
for(int i=4;i<MAX;i+=2)
{
isPrime[i]=0;
}
for(int i=3;i<MAX;i+=2)
{
if(isPrime[i])
{
primes.push_back(i);
for(int j=2*i;j<MAX;j+=i)
{
isPrime[j]=0;
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
init();
cout<<primes.size()<<endl;
cout<<primes[10000]<<endl;
return 0;
}