//
#include<bits/stdc++.h>
using namespace std;
const int N=1e8+9;
int prime[N];
bool judge[N];
void sieve()
{
memset( prime,0,sizeof( prime ) );
memset( judge,0,sizeof( judge ) );
int i,j,cnt=0;
judge[1]=1; // judge 也可以用来预判断 prime
for( i=2;i<N;i++ )
{
if( judge[i]==0 ) prime[cnt++]=i;
for( j=0;j<cnt && i<=N/prime[j];j++ )
{
judge[ i*prime[j] ]=1;
if( i%prime[j]==0 ) break;
}
}
}
int main()
{
sieve(); int n,q,x;
while( ~scanf("%d%d",&n,&q) )
{
while( q-- )
{
scanf("%d",&x);
printf("%d\n",prime[x-1]);
}
}
return 0;
}
洛谷_P3383 【模板】线性筛素数_欧氏筛
猜你喜欢
转载自blog.csdn.net/qq_63173957/article/details/123933893
今日推荐
周排行