소수를 크기 순으로 나열하면 2, 3, 5, 7, 11, 13, ... 과 같이 됩니다.

이 때 10,001번째의 소수를 구하세요.





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
 
int main() {
    int count, countb = 0;
    long i;
 
    for (i = 2; i < 100000000; i++) {
        count = 0;
        for (long j = 1; j <= i; j++)
            if (i%j == 0)
                count++;
 
        if (count == 2)
            countb++;
 
        if (countb == 10001) {
            cout << i;
            return 0;
        }
    }
}
cs


+ Recent posts