-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6588.cpp
50 lines (39 loc) · 1.02 KB
/
6588.cpp
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
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<bool> prime(1000001, true); // 인덱스 0부터 1000000까지 사용
// 에라토스테네스의 체 이용하기
void findPrime() {
prime[0] = prime[1] = false;
for (int i = 2; i * i <= 1000000; ++i) {
if (prime[i]) {
for (int j = i * i; j <= 1000000; j += i) {
prime[j] = false;
}
}
}
}
int main() {
//입출력 속도 향상
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
findPrime();
int input;
cin >> input;
while(input != 0) {
bool check = false;
for(int i=3; i <= input/2; i++) {
if(prime[i] && prime[input-i]) {
cout << input << " = " << i << " + " << input-i << '\n';
check = true;
break;
}
}
if(!check) {
cout << "Goldbach's conjecture is wrong." << '\n';
}
cin >> input;
}
}