AcWing 3497. 质数
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
int t, n, m, k, l, r, op, x, y;
bool g[N];
int f[N];
void solve() {
g[1] = true;
x = sqrt(N);
for (int i = 2; i <= x; i++) {
if (g[i])continue;
for (int j = i * i; j < N; j += i) {
g[j] = true;
}
}
for (int i = 1; i < N; i++) {
if (!g[i])f[++m] = i;
}
while (cin >> k) {
cout << f[k] << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}