法一:
代码如下:
#include <iostream>
#include <cmath>
using namespace std;bool check(int x) {for (int i = 2; i <= sqrt(x); i++)if (x % i == 0)return false;return true;
}int main() {int n;int ans = 0;for (int i = 2; i; i++) {if (check(i)) {ans++;if (ans == 2019) {cout << i << endl;return 0;}}}return 0;}
法二:
#include <iostream>
using namespace std;
const int N = 100100;
bool vis[N];void fff() {for (int i = 2; i <= N - 1; i++)if (!vis[i])for (int j = 2 * i; j <= N - 1; j += i) {vis[j] = true;}
}int main() {fff();int ans = 0;for (int i = 2; i <= N - 1; i++) {if (!vis[i]) {ans++;if (ans == 2019) {cout << i << endl;return 0;}}}return 0;
}