-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuler7.cpp
More file actions
42 lines (35 loc) · 810 Bytes
/
Euler7.cpp
File metadata and controls
42 lines (35 loc) · 810 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
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <math.h>
using namespace std;
bool isprime(unsigned long int num){
if(num == 2 || num == 3){
return true;
}
if(num < 2){
return false;
}
if(num%2 == 0 || num%3 == 0){
return false;
}
for(unsigned long int i = 4; i <= pow(num, .5); i++ ){
if(num%i == 0){
return false;
}
}
return true;
}
int main(){
int index = 0;
int result = 2;
for(unsigned int i = 2; index < 10001; i++){
if(isprime(i)){
index++;
result = i;
//at this point in the first iteration index = 1 (for 1st) and result = 2.
//2 is the 1st prime
}
}
cout<<"The 10001st prime is: "<< result << endl;
}