试除法判断质数
作者:
jy9
,
2024-09-02 22:10:37
,
所有人可见
,
阅读 2
掉个个就AC啦?
#include <iostream>
using namespace std;
bool isprime(int x){
if(x < 2) return false;
for (int i = 2; i <= x / i; i ++ ){
if(x % i == 0)return false;
}
return true;
}
int main(){
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ){
int t;
cin >> t;
if(isprime(t))cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
bool isprime(int x){
if(x < 2) return false;
for (int i = 2; i * i <= x; i ++ ){
if(x % i == 0)return false;
}
return true;
}
int main(){
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ){
int t;
cin >> t;
if(isprime(t))cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
丐版,13/14
无法通过以下数据
1
2147483647