题解 | 素数判断
素数判断
https://www.nowcoder.com/practice/5ab1b9690af047699e96c87dee65def4
#include <iostream>
using namespace std;
int main() {
int a;
cin>>a;
for(int b;a>0;a--)
{
cin>>b;
int c=2;
if (b==1)
{
cout<<"No"<<'\n';
}
else{
for(;c<=b;c++){
if (c==b){
cout<<"Yes"<<'\n';
break;
}
else{
if (b%c!=0){
continue;
}
else{
cout<< "No"<<'\n';
break;
}
}
}
}
}
return 0;
}
// 64 位输出请用 printf("%lld")
终于写出来了
查看2道真题和解析