题解 | #素数判定#

素数判定

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

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;

int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        if (n <= 0 || n == 1) {
            printf("no\n");
            continue;
        }
        int i;
        for (i = 2; i <= n / 2; i++) {
            if (n % i == 0) {
                printf("no\n");
                break;
            }
        }
        if (i > n / 2) {
            printf("yes\n");
        }
    }
    return 0;
}

全部评论

相关推荐

半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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