注意点:
- 0和1都不是素数,所以在判断时要特判<=1的数字.
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int x){
if(x<=1)return 0;
for(int i=2;i<=sqrt(x);i++){
if(!(x%i))return 0;
}
return 1;
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int tmp;
scanf("%d",&tmp);
cout<<(isPrime(tmp)?"Yes":"No")<<endl;
}
return 0;
}