题解 | 判断质数
判断质数
https://www.nowcoder.com/practice/9f418ff48b5e4e879f398352bed6118d
#include<iostream>
#include<cmath>
using namespace std;
bool is_prime(long long n){
if(n<=1){
return false;
}
for(long long i=2;i*i<=n;++i){
if(n%i==0){
return false;
}
}
return true;
}
int main(){
long long n;
cin>>n;
if(is_prime(n)){
cout<<"Yes"<<endl;
}
else {
cout<<"No"<<endl;;
}
}
查看11道真题和解析