https://www.luogu.org/problemnew/show/P3383

相信大家都会埃式筛选,这里就不赘述了,先放个板子,以后容易找。

//欧拉素数筛选 
#include <cstdio>
#include <cstring> 
#define N 10000005
#define LL long long
LL prime[N];
int p[N];
void primeTable(int n){
    int k = 1;
    memset(p,1,sizeof(p));
    p[0] = 0;
    p[1] = 0;
    for(int i=2;i<=n;i++){
        if(p[i]){
            prime[k++] = i;
        }
        for(int j=1;j < k;j++){
            if(i*prime[j]>N) break;
            p[i*prime[j]] = 0;
            if(i%prime[j]==0) break;
        }
    }
}
int n,m;
int main(){
    int num;
    scanf("%d%d",&n,&m);
    primeTable(n);
    while(m--){
        scanf("%d",&num);
        printf("%s\n",p[num]?"Yes":"No");
    }
    return 0;
}