RT
代码如下
#include<stdio.h>
#include<cctype>
using namespace std;
const int N = 100000000;
const int M = 1000000;
int prime[M + 5];
bool v[N + 5];
int tot;
int n, m;
inline void pre()
{
v[1] = 1;
for (int i = 2; i <= N; ++i)
{
if(!v[i])
prime[++tot] = i;
for (int j = 1; j <= tot && 1ll*prime[j] * i <= N; ++j)
{
v[1ll*i * prime[j]] = 1;
if (i % prime[j] == 0) break;
}
}
}
inline int read()
{
int x=0;short w=0;char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return w ? -x : x;
}
int main ()
{
n = read(), m = read();
pre();
while(m--)
{
int x = read();
printf("%d\n", prime[x]);
}
return 0;
}