forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
20 lines (17 loc) · 515 Bytes
/
1.cpp
File metadata and controls
20 lines (17 loc) · 515 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;
// 소수 판별 함수(2이상의 자연수에 대하여)
bool isPrimeNumber(int x) {
// 2부터 x의 제곱근까지의 모든 수를 확인하며
for (int i = 2; i <= (int) sqrt(x); i++) {
// x가 해당 수로 나누어떨어진다면
if (x % i == 0) {
return false; // 소수가 아님
}
}
return true; // 소수임
}
int main() {
cout << isPrimeNumber(4) << '\n';
cout << isPrimeNumber(7) << '\n';
}