#include #include using namespace std; bool pan[100000001] = { 0 }; int chu[1000001] = { 0 }, now = 0; //线性筛 void findsu(int n){ for (int i = 2; i <= n; i++) { if (!pan[i]) { chu[++now] = i; } for (int j = 1; j <= now && i * chu[j] <= n; j++) { pan[i * chu[j]] = 1; //重要!!确保用最大的因数来乘如用6*2=12而避免4*3=12重复计算 if (i % chu[j] == 0) { break; } } } } int main() { int n, e; scanf("%d%d",&n,&e); findsu(n);//筛出素数 for (int i = 1; i <= e; i++) { scanf("%d",&n); printf("%d\n",chu[n]); } }