线性筛
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #include<queue> #include<set> #define maxint (2147483647) #define l(a) ((a)<<1) #define r(a) ((a)<<1|1) #define b(a) (2<<(a)) #define rep(i,a,b) for(int i=a;i<=(b);i++) #define clr(a) memset(a,0,sizeof(a)) typedef long long ll; using namespace std; int readint(){ int t=0,f=1;char c=getchar(); while(!isdigit(c)){ if(c=='-') f=-1; c=getchar(); } while(isdigit(c)){ t=(t<<3)+(t<<1)+c-'0'; c=getchar(); } return t*f; } const int maxn=10000009; int n,m,t,pri[maxn/10],cnt; bool p[maxn]; void getpri(){ p[1]=1; rep(i,2,n){ if(!p[i]) pri[cnt++]=i; rep(j,0,cnt-1){ if(i*pri[j]>n) break; p[i*pri[j]]=1; if(i%pri[j]==0) break; } } } int main(){ //freopen("#input.txt","r",stdin); //freopen("#output.txt","w",stdout); n=readint();m=readint(); getpri(); while(m--){ t=readint(); puts((!p[t])?"Yes":"No"); } //fclose(stdin); //fclose(stdout); return 0; }