10 이하의 소수를 모두 더하면 2 + 3 + 5 + 7 = 17 이 됩니다.

이백만(2,000,000) 이하 소수의 합은 얼마입니까?





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;
 
int main() {
    int i, count, result = 0;
 
    for (i = 2; i <= 2000000; i++) {
        count = 0;
        for (int j = 1; j <= i; j++)
            if (i%j == 0)
                count++;
        if (count == 2)
            result += i;
    }
    cout << result << endl;
}
cs


+ Recent posts