/************************************************
Programmer : Muhammad Azri bin Jasni @ Abdul Rani
Program : project euler problem 10_2.cpp
Link : http://projecteuler.net/problem=10
Description: My second attempt by refering to answer available in internet
Note : Must use long long to store the sum. or it will overflow.
*************************************************
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
*************************************************/
#include <iostream>
#include <math.h>
using namespace std;//im using devc++
//bool isPrime(long);
int main()//a good practice to use int main() instead of void main()
{
/*based on this : http://kahthong.com/2011/12/project-euler-problem-10*/
long long sum = 2;
long max = 2000000;
for (long i=2;i<max;i++)
{
if (i % 2 != 1)
{
continue;
}
long d = 3;
double x = sqrt(i);
while ( (i%d != 0) && (d<x) )
{
d += 2;
}
if (((i%d==0&&i!=d)*1)==0)
{
sum+=i;
}
}
cout << sum << endl;
//system("PAUSE");
return 0;
}