___xuzhimo___ @ 2024-11-03 21:10:03
#include <bits/stdc++.h>
using namespace std;
int n, m, imp = 0;
bool a[100000005];
int b[1000005];
int ans[1000005];
int main() {
std::ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> b[i];
}
for (int i = 2; i <= n; i++) {
if (a[i] == false) {
ans[++imp] = i;
}
for (int j = 1; j <= imp && i * ans[j] <= n; j++) {
a[i * ans[j]] = true;
if (i % ans[j] == 0)
break;
}
}
for (int i = 1; i <= m; i++) {
cout << ans[b[i]] << "\n";
}
return 0;
}
by Twlight! @ 2024-11-03 21:17:57
数组开小了
by Twlight! @ 2024-11-03 21:20:45
筛到