Baekjoon(C++)
[C++]백준 알고리즘 9020번
DanielSoliph
2021. 7. 27. 23:50
풀이는 아래와 같다.
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
38
39
40
|
#include <iostream>
#include <cmath>
using namespace std;
int prime(int num){
int root = (int)sqrt(num);
if(num == 2 || num == 3){
return 1;
}else{
for(int i=2; i<=root; i++){
if(num%i == 0){
return 0;
}
if(i == root){
return 1;
}
}
}
return 0;
}
int main()
{
int T;
cin >> T;
for(int t=0; t<T; t++){
int n;
cin >> n;
int a,b;
for(int i=2; i<=n/2; i++){
if(prime(i) && prime(n-i)){
a = i; b = n-i;
}
}
cout << a << ' ' << b << '\n';
}
return 0;
}
|
cs |
반응형