欧拉计划第7题题解

10001st prime

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

第10001个素数

列出前6个素数,它们分别是2、3、5、7、11和13。我们可以看出,第6个素数是13。

第10,001个素数是多少?

解题思路

可以枚举每一个数,然后得到第10001个素数;也可以用素数筛法。

这里通过枚举来求第10001个素数。

实现代码如下:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 10001000;
bool np[maxn];
int c;
bool check(long long a) {
    if (a < 2) return false;
    for (long long i = 2; i <= a/i; i ++)
        if (a % i == 0)
            return false;
    return true;
}
int main() {
    long long i;
    for (i = 2; c < 10001; i ++)
        if (check(i))
            c ++;
    cout << i << endl;
    return 0;
}

答案为 \(104744\)

posted @ 2020-02-17 18:07  quanjun  阅读(193)  评论(0编辑  收藏  举报