题解 | #素数判定#

素数判定

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

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

int main(){
    int x;
    cin >> x;
    if(x < 2) cout << "no" << endl;
    else {
        for(int i = 2 ; i<=sqrt(x);i++){
            if(x % i == 0) {
                cout << "no" << endl;
                return 0;
            }
        }
        cout << "yes" << endl;
    }
}

全部评论

相关推荐

鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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