-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoldbach.java
More file actions
42 lines (33 loc) · 1.08 KB
/
Copy pathGoldbach.java
File metadata and controls
42 lines (33 loc) · 1.08 KB
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
package math;
import java.util.*;
import java.util.Scanner;
public class Goldbach {
public static final int MAX = 1000000;
public static void main(String[] args) {
//#6588_°ñµå¹ÙÈåÀÇ ÃßÃø
Scanner sc = new Scanner(System.in);
boolean [] isPrime = new boolean[MAX+1];
Arrays.fill(isPrime, true);
for(int i = 2; i <= MAX; i++) {
for(int j = i * 2; j <= MAX; j += i) {
if(!isPrime[j]) continue;
isPrime[j] = false;
}
}
while(true) {
int n = sc.nextInt();
boolean ok = false;
if(n == 0)
break;
for(int i = 2; i <= n/2; i++) {
if(isPrime[i] && isPrime[n-i]) {
System.out.println(n + " = " + i + " + " + (n-i));
ok = true;
break;
}
}
if(!ok)
System.out.println("Goldbach's conjecture is wrong.");
}
}
}