https://www.luogu.com.cn/problem/P3383
#include <bits/stdc++.h> using namespace std; const int M = 1e8 + 10; int a[100000010], k = 0; bool f[100000010]; void fun(int n) { for (int i = 2; i <= n; i++) { if (f[i] == 0) a[++k] = i; for (int j = 1; j <= k && i * a[j] <= n; j ++) { f[i * a[j]] = 1; if (i % a[j] == 0) break; } } } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int t, n, x; cin >> n >> t; fun(n); while (t--) { cin >> x; cout << a[x] << "\n"; } return 0; }