jingliang_youxi @ 2024-10-10 09:07:41
#include <bits/stdc++.h>
using namespace std;
int pri[100001], cnt;
bool st[100001];
void a(int n) {
for (int i = 2; i <= n; i++) {
if (!st[i]) {
pri[cnt++] = i;
}
for (int j = 0; pri[j] <= n / i; j++) {
st[pri[j]*i] = true;
if (i % pri[j] == 0)
break;
}
}
}
int main() {
std::ios::sync_with_stdio(0);
int n, m, p[100001];
cin >> n >> m;
a(n);
while (m--) {
int k = 0;
cin >> k;
cout << pri[k] << endl;
}
return 0;
}
by _mei_tou_nao_ @ 2024-10-10 09:14:40
楼主坐标机房,忘记数组下标开始为0,已解决。
by _mei_tou_nao_ @ 2024-10-10 09:15:03
此贴结