Skip to content

Commit 0ea6928

Browse files
committed
[Silver I] Title: 골드바흐의 추측, Time: 1176 ms, Memory: 39692 KB -BaekjoonHub
1 parent 66060fe commit 0ea6928

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# [Silver I] 골드바흐의 추측 - 6588
2+
3+
[문제 링크](https://www.acmicpc.net/problem/6588)
4+
5+
### 성능 요약
6+
7+
메모리: 39692 KB, 시간: 1176 ms
8+
9+
### 분류
10+
11+
수학, 정수론, 소수 판정, 에라토스테네스의 체
12+
13+
### 제출 일자
14+
15+
2025년 10월 27일 11:02:13
16+
17+
### 문제 설명
18+
19+
<p>1742년, 독일의 아마추어 수학가 크리스티안 골드바흐는 레온하르트 오일러에게 다음과 같은 추측을 제안하는 편지를 보냈다.</p>
20+
21+
<blockquote>4보다 큰 모든 짝수는 두 홀수 소수의 합으로 나타낼 수 있다.</blockquote>
22+
23+
<p>예를 들어 8은 3 + 5로 나타낼 수 있고, 3과 5는 모두 홀수인 소수이다. 또, 20 = 3 + 17 = 7 + 13, 42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23 이다.</p>
24+
25+
<p>이 추측은 아직도 해결되지 않은 문제이다.</p>
26+
27+
<p>백만 이하의 모든 짝수에 대해서, 이 추측을 검증하는 프로그램을 작성하시오.</p>
28+
29+
### 입력
30+
31+
<p>입력은 하나 또는 그 이상의 테스트 케이스로 이루어져 있다. 테스트 케이스의 개수는 100,000개를 넘지 않는다.</p>
32+
33+
<p>각 테스트 케이스는 짝수 정수 n 하나로 이루어져 있다. (6 ≤ n ≤ 1000000)</p>
34+
35+
<p>입력의 마지막 줄에는 0이 하나 주어진다.</p>
36+
37+
### 출력
38+
39+
<p>각 테스트 케이스에 대해서, n = a + b 형태로 출력한다. 이때, a와 b는 홀수 소수이다. 숫자와 연산자는 공백 하나로 구분되어져 있다. 만약, n을 만들 수 있는 방법이 여러 가지라면, b-a가 가장 큰 것을 출력한다. 또, 두 홀수 소수의 합으로 n을 나타낼 수 없는 경우에는 "Goldbach's conjecture is wrong."을 출력한다.</p>
40+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
static boolean isPrime[];
7+
8+
public static void main(String[] args) throws Exception {
9+
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
12+
isPrime = new boolean[1000001];
13+
Arrays.fill(isPrime, true);
14+
isPrime[0] = isPrime[1] = false;
15+
16+
for(int i = 2; i*i <=1000000; i++) {
17+
if(isPrime[i]) {
18+
for(int j = i * i; j <= 1000000; j+=i) {
19+
isPrime[j] = false;
20+
}
21+
}
22+
}
23+
24+
while(true) {
25+
int N = Integer.parseInt(br.readLine());
26+
27+
if(N ==0) break;
28+
29+
boolean found = false;
30+
for(int i = 3; i <=N/2; i+=1) {
31+
if(isPrime[i] &&isPrime[N-i]) {
32+
System.out.println(N + " = " + i + " + " + (N-i));
33+
found = true;
34+
break;
35+
}
36+
}
37+
if(!found) {
38+
System.out.println("Goldbach's conjecture is wrong.");
39+
}
40+
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)