一二三四五 上山打老虎

天梯赛L1-028 判断素数 (10 分)

链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805106325700608

暴力判素数故意卡i*i<=x

代码:

#include<bits/stdc++.h>

using namespace std;
bool check(int x){
    if(x==1)return false;
    for(int i=2;i<=sqrt(x);i++){//故意卡i*i<=x
        if(x%i==0)return false;
    }
    return true;
}
int main (){
    
    int n,num;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>num;
        if(check(num))cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
}
posted @ 2021-04-21 16:50  黒川川  阅读(114)  评论(2)    收藏  举报