-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy path6.7.cpp
More file actions
37 lines (33 loc) · 812 Bytes
/
6.7.cpp
File metadata and controls
37 lines (33 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* 题目名称:素数判断
* 题目来源:哈尔滨工业大学复试上机题
* 题目链接:http://t.cn/AiCuWE0Q
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool Judge(int x) { //判断是否为质数
if (x < 2) { //小于2必定不是
return false;
}
int bound = sqrt(x); //确定判断上界
for (int i = 2; i <= bound; ++i) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (Judge(n)) {
printf("yes\n");
} else {
printf("no\n");
}
}
return 0;
}