Project Euler - problem 007

August 1st, 2007 by Daniel

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 10001st prime number?

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
 
 
#include <iostream>
#include <vector>
using namespace std;
 
#define numbersOfPrimes 10001
//declare methods
bool isPrimeNumber(int num);
 
 
 
 
int main ()
{
 
int res(1), ant(1) ;
 
 
while(ant < numbersOfPrimes){
res+= 2;
if (isPrimeNumber(res) ){
ant++;
}
 
}
 
cout << "resultatet er ";
cout << res << "\n";
 
return 0;
}vector<int> numbers;
 
 
 
// methods
bool isPrimeNumber(int num){
// static vector<int> primeNumbers;
 
for(int i = 3; i < num ; i+=2){
if( num % i == 0){
return false;
}
}
 
//primeNumbers.push_back(num);
 
return true;
}

1 Response to “Project Euler - problem 007”

  1. I can give you my class which I used to solve problem10.
    Just send me an e-mail.

Leave a Response