文章

81

粉丝

2

获赞

450

访问

8.2k

头像
判断素数 题解:
P1013 贵州大学机试题
发布于2026年3月14日 23:51
阅读数 107

#include <iostream>
using namespace std;

bool isPrime(int x){
	if(x < 2) return false;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0)
			return false;
    }
    return true;
}

int main(){
	int n;
	cin >> n;
	
	while(!isPrime(n)){
		n++;
		}
	cout << n;
	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发