文章

211

粉丝

0

获赞

1069

访问

35.8k

头像
判断素数 题解:
P1013 贵州大学机试题
发布于2026年2月5日 17:07
阅读数 214

#include<bits/stdc++.h>
using namespace std;
bool isPrime(int x) {
    if (x <= 1) 
		return false;
    for (int i = 2; i * i <= x; ++i)
        if (x % i == 0) 
			return false;
    return true;
}
int main(){
	int n;
	cin >> n;	
	if(isPrime(n)){
		cout << n;
		return 0;
	}else{	
		for(int i=n+1;;i++){
			if(isPrime(i)){
				cout << i;
				return 0;
			}	
		}	
	}
}	

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发