-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.cpp
More file actions
55 lines (40 loc) · 710 Bytes
/
Copy path7.cpp
File metadata and controls
55 lines (40 loc) · 710 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
48
49
50
51
52
53
54
55
/*
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
*/
#include <iostream>
#include <cmath>
using namespace std;
#define N 10001
typedef unsigned long long int big;
bool isPrime(big number){
bool flag = false;
for(big i=2; i<=sqrt(number); ++i)
{
// condition for nonprime number
if(number%i==0)
{
flag=true;
break;
}
}
return !flag;
}
void start(){
big i=3;
int counter = 1;
while(true){
if(isPrime(i)){
counter++;
}
if(counter == N){
break;
}
i+=2;
}
cout << i;
}
int main(void){
start();
return 0;
}