文章

8

粉丝

0

获赞

72

访问

1.3k

头像
判断素数 题解:
P1013 贵州大学机试题
发布于2026年3月18日 20:32
阅读数 103

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

bool is(int n){
    if(n<=1) return false;
    else if(n==2) return true;
    else if(n%2==0) return false;
    else{
        for(int i=2;i<n;i++){
            if(n%i==0) return false;
        }
    }
    return true;
}

int main(){
    int n;
    scanf("%d",&n);
    
    if(is(n)==true) printf("%d\n",n);
    else{
        while(is(n)==false){
            n++;
        }
        printf("%d\n",n);
    }

    return 0;
}

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发