Deprecated: Assigning the return value of new by reference is deprecated in /customers/dahoiv.net/dahoiv.net/httpd.www/programmering/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /customers/dahoiv.net/dahoiv.net/httpd.www/programmering/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /customers/dahoiv.net/dahoiv.net/httpd.www/programmering/wp-includes/theme.php on line 507
Project Euler - problem 010

Project Euler - problem 010

August 1st, 2007 by Daniel Høyer Iversen

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below one million.

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
 
 
#include <iostream>
#include <vector>
using namespace std;
 
#define sizeOfPrime 1000000
 
//declare methods
bool isPrimeNumber(int num);
 
int main ()
{
 
long long int res(1);
 
for(int currentPrime = 1; currentPrime< sizeOfPrime; currentPrime += 2){
if (isPrimeNumber(currentPrime) ){
res += currentPrime;
}
}
 
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-1)*(i-1) < num ; i+=2){
if( num % i == 0){
return false;
}
}
 
//primeNumbers.push_back(num);
 
return true;
}
Do you want to use this code?

3 Responses to “Project Euler - problem 010”

  1. Mostafa

    nice ,, thx for good code

  2. Mostafa

    but this code have 21 error ?! :@

  3. Owajigbanam Ogbuluijah

    DId you just copy-paste, Mostafa? Cos if you did, say hello to GCC cos she will complain like an angry girlfriend.

Leave a Response