题解 | 素数判断

素数判断

https://www.nowcoder.com/practice/5ab1b9690af047699e96c87dee65def4

#include <bits/stdc++.h>
using namespace std;

int main() {
    int t,n;
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>n;
        if(n==1){
            cout<<"No"<<endl;
            continue;
        }else if(n==2){
            cout<<"Yes"<<endl;
            continue;
        }
        
        bool flag=true;
        for (int j=2;j<=sqrt(n);j++) {
            if(n%j==0){
                cout<<"No"<<endl;
                flag=false;
                break;
            }
        }
        if(flag){
            cout<<"Yes"<<endl;
        }
    }


}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
哞客37422655...:github如果提交不是很多 可以不写 可能会是减分项。之前听别人讲过的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务