-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9020.cpp
More file actions
58 lines (53 loc) · 800 Bytes
/
9020.cpp
File metadata and controls
58 lines (53 loc) · 800 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// 9020. 골드바흐의 추측
// 2019.08.17
// 수학
#include<iostream>
using namespace std;
// 소수 구하기
bool isPrime[10001];
void check()
{
isPrime[0] = false;
isPrime[1] = false;
for (int i = 2; i <= 10000; i++)
{
for (int j = i * i; j <= 10000; j += i)
{
if (isPrime[j])
{
isPrime[j] = false;
}
}
}
}
int main()
{
fill(isPrime, isPrime + 10000, true);
check();
int t;
cin >> t;
while (t-- > 0)
{
int n;
cin >> n;
int a = 0;
int b = 0;
// n/2까지 중단없이 진행하면
// 두 소수의 차이가 가장 작은 것이 된다.
for (int i = 2; i <= n/2; i++)
{
int tmp = n;
if (isPrime[i])
{
tmp -= i;
if (isPrime[tmp])
{
a = i;
b = tmp;
}
}
}
cout << a << " " << b << endl;
}
return 0;
}