-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,50 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <cmath> | ||
#include <vector> | ||
|
||
/* | ||
b - a가 가장 큰 경우가 언제일지 잘 생각해보아요! | ||
n = a + b를 만족시키는 두 소수들을 어디서부터 탐색하면 좋을까요? | ||
*/ | ||
using namespace std; | ||
|
||
int getPrime() { | ||
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) { | ||
getPrime(); | ||
|
||
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; | ||
} | ||
|
||
} |