Skip to content

Instantly share code, notes, and snippets.

@BrendenHJH
Created May 10, 2018 03:35
Show Gist options
  • Save BrendenHJH/551358961518429bd64a746dc37d99cc to your computer and use it in GitHub Desktop.
Save BrendenHJH/551358961518429bd64a746dc37d99cc to your computer and use it in GitHub Desktop.
백준 6588 골드바흐의 추측
import java.util.Scanner;
public class Main {
public static final int MAX = 1000000;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean[] isPrime = new boolean[MAX+1];
for(int i = 2; i <= MAX; i++) {
isPrime[i] = 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.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment