(Problem 10)Summation of primes
2013-07-24 00:06
302 查看
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Find the sum of all the primes below two million.
#include<stdio.h> #include<string.h> #include<math.h> #include<ctype.h> #include<stdlib.h> #include<stdbool.h> #define N 2000000 bool prim(int n) { int i; for(i=2; i*i<=n; i++) { if(n%i==0) return false; } return true; } int main() { int i; long long sum=2; for(i=3; i<=N; i=i+2) { if(prim(i)) { sum+=i; } } printf("%lld\n",sum); return 0; }
Answer: | 142913828922 |
相关文章推荐
- (Problem 10)Summation of primes
- (Problem 10)Summation of primes
- Problem 10:Summation of primes
- projecteuler---->problem=10----Summation of primes
- Problem 10:Summation of primes
- projecteuler---->problem=10----Summation of primes
- 10 Summation of primes - Project Euler
- projecteuler---->problem=10----Summation of primes
- 欧拉计划(10)Summation of primes
- Project Euler Problem 10: Summation of primes
- 【Project Euler】【Problem 10】Summation of primes
- Problem 10 of Find the sum of all the primes below two million.
- Problem 10 Summation of primes
- project euler problem 10:Summation of primes
- hdu 5104 Primes Problem(素数判定)
- Summation of Four Primes(歌德巴赫猜想)
- HDU 5104 Primes Problem(素数打表)
- Problem 10 Summation of primes (素数和)
- The Secret To 10 Million Concurrent Connections -The Kernel Is The Problem, Not The Solution
- Primes Problem (HDU5104) 素数问题