洛谷3383
1 #include<cstdio> 2 #include<algorithm> 3 #include<cmath> 4 using namespace std; 5 const int maxn=10000010; 6 int n,m; 7 bool a[maxn]; //a[i]为1表示i不是质数 8 void read(int &k){ 9 k=0; int f=1; char c=getchar(); 10 while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar(); 11 while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar(); 12 k*=f; 13 } 14 int main(){ 15 read(n); read(m); a[1]=1; //1不是质数,要特判 16 for (int i=1;i*i<=n;i++) if (!a[i]) 17 for (int j=i<<1;j<=n;j+=i) a[j]=1; 18 for (int i=1,x;i<=m;i++) read(x),printf(a[x]?"No ":"Yes "); 19 return 0; 20 }