欧拉计划(10)Summation of primes

来源:互联网 发布:阿里云 幕布申请 编辑:程序博客网 时间:2024/05/18 03:46

【题目】

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

Find the sum of all the primes below two million.

【翻译】

10以下的质数的和是2 + 3 + 5 + 7 = 17.

找出两百万以下所有质数的和。

【思路】依旧暴力法 

【代码】

bool isPrime( int value){if(value==2)  return true;if(value<2 || (!(value&1)))return false;for(int i=2;i<(int)sqrt(value)+1;i++){if(value%i==0){return false;}}return true;}void test10(){long long int sum=2;for(int i=3;i<2000000;i+=2)if(isPrime(i))sum+=i;cout<<sum<<endl;}

【答案】本题答案为 142913828922。

0 0
原创粉丝点击