注意事项:无。 代码: 12345678910111213bool notpr[MAXn + 10]; int cntpr, pr[MAXn / 10 + 100];void evapr(int n) { notpr[1] = 1; for (int i = 2; i <= n; ++i) { if (notpr[i] == 0) { pr[++cntpr] = i; } for (int j = 1, toppj = n / i; j <= cntpr && pr[j] <= toppj; ++j) { notpr[i * pr[j]] = 1; if (i % pr[j] == 0) break; } }} Luogu P3383 【模板】线性筛素数 代码: 12345678910111213141516171819202122232425262728293031323334353637#include<bits/stdc++.h>using namespace std;const int MAXn = 1e8;template <typename T>inline void read(T &a) { char c;for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar());bool f = c == '-';T x = f ? 0 : (c ^ '0');for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) {x = x * 10 + (c ^ '0');}a = f ? -x : x;}template <typename T, typename ...Argv>inline void read(T &a, Argv &...argv) { read(a), read(argv...);}bool notpr[MAXn + 10]; int cntpr, pr[MAXn / 10 + 100];void evapr(int n) { notpr[1] = 1; for (int i = 2; i <= n; ++i) { if (notpr[i] == 0) { pr[++cntpr] = i; } for (int j = 1, toppj = n / i; j <= cntpr && pr[j] <= toppj; ++j) { notpr[i * pr[j]] = 1; if (i % pr[j] == 0) break; } }}int n, m;signed main() { read(n, m); evapr(n); for (int i = 1, x; i <= m; ++i) { read(x); printf("%d\n", pr[x]); } return 0;}