Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Prime specific sum
All primes less than 10 and is 2 + 3 + 5 + 7 = 17.
Find all primes less than two million and.
Problem-solving ideas
Not a particularly good idea, under the milk can think of is calculated to enumerate all the prime numbers less than 2 million, then seek these primes.
Codes are as follows:
#include <bits/stdc++.h>
using namespace std;
bool check(int a) {
if (a < 2) return false;
for (int i = 2; i*i <= a; i ++)
if (a % i == 0) return false;
return true;
}
long long sum;
int main() {
for (int i = 2; i < 2000000; i ++)
if (check(i))
sum += i;
cout << sum << endl;
return 0;
}
Get answers to \ (142 913 828 922 \) .