I was solving Euler problem no. 10 that asks to find sum of all primes below 2million.
I am getting different results on using sqrt
and pow
functions.
Using sqrt
gives the correct answer, plus using pow function takes more time. Here is my code.
for(sum=0,i=3;i<=2000000;i+=2)
{
for(j=3;j<=sqrt(i);j++)
if(i%j==0)
break;
if(j>sqrt(i))
sum+=i;
}
sum+=2;
std::cout << "
Sum = " << sum;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…