-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem7.cpp
52 lines (41 loc) · 880 Bytes
/
problem7.cpp
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
48
49
50
51
52
//10001st prime
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> stored;
int n = 9999;
int k =0;
int start = 5;
while(1){
int cand1 = start, cand2= start+2;
bool c1=true, c2=true;
for(int i = 0; i<stored.size() && (c1 || c2);i++){
if (cand1%stored[i]==0 && c1){
c1 = false;
}
if (cand2%stored[i]==0 && c2){
c2 = false;
}
}
if(c1){
stored.push_back(cand1);
k++;
}
if(k==n){
cout<<cand1<<endl;
break;
}
if(c2){
stored.push_back(cand2);
k++;
}
if(k==n){
cout<<cand2<<endl;
break;
}
start = start+6;
}
return 0;
}