1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: 543 Goldbach's Conjecture
* Link: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=484
*
* @author Stefan Gohlke
* @version 1.0, 10/14/2009
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.272
*/

package golbach_acc;

import java.util.Scanner;

public class Main {

public static void main (String[] args)
{
golbach();
}

public static void golbach()
{
Scanner scanner = new Scanner(System.in);
int n = 0;
n = scanner.nextInt();
while (n != 0)
{
if (n >=6 && n < 1000000)
{
//höchste Primzahl nach n ermitteln
int naechsthoechstePrim = n;
boolean istPrim= false;
while (!istPrim)
{
naechsthoechstePrim--;
if (naechsthoechstePrim ==2) System.out.println("Goldbach's conjecture is wrong.");
else if (pruefPrim(naechsthoechstePrim))
{
int a = n-naechsthoechstePrim;
if ( a > 1 && pruefPrim(a) )
{
System.out.println(n + " = "+ a + " + " + naechsthoechstePrim );
istPrim= true;
}
}
}
}

n = scanner.nextInt();
}
}

public static boolean pruefPrim(int zuPruefendeZahl)
{
for (int i = 2; i<= Math.sqrt(zuPruefendeZahl); i++)
{
if (zuPruefendeZahl%i == 0) return false;
}
return true;
}
}

2.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;


/**
*
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem 543 GoldBach's Conjecture
*
* @author Petersen Jan
* Status : Accepted
* Runtime: 0.804
*/
public class Main543 {

/**
* @param args
*/
public static void main(String[] args) throws Exception{

int maxin = 1000000;
// maybe not efficient but ...
boolean[] primarray = new boolean[maxin];
// set all true
Arrays.fill(primarray, true);
// 0 and 1 are no primes
primarray[0] = false;
primarray[1] = false;
int actualprime = 2;

// find and mark all prime numbers after the Sieve of Eratosthenes algorithm
while(actualprime*actualprime <= primarray.length) {
if(primarray[actualprime]) {
for(int j = actualprime+actualprime; j < primarray.length; j+=actualprime)
primarray[j] = false;
}
actualprime++;
}
// for (int i = 0; i < primarray.length; i++) {
// if(primarray[i])
// System.out.println(i);
// }

// Buffered reader for input
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String line = reader.readLine();
int innumber = Integer.parseInt(line);
if(innumber == 0) {
break;
}
else if (innumber < 4 || innumber > maxin) {
throw new Exception("Parameter out of range. input must be 6 <= n < " + maxin);
}
else if(innumber % 2 != 0) {
throw new Exception("Entered number is not even.");
}


// find the first prime number ( at least 2 ) smaller than the input
// -2 is for not finding a prime number just 1 smaller than the input
int nextsmallerprim = innumber-2;
int littleprim = 0;

// alles durchsuchen bis die große und die kleine zahl ne primzahl ist
while(!(primarray[nextsmallerprim] && primarray[littleprim])) {
while(!primarray[nextsmallerprim])
nextsmallerprim --;

littleprim = innumber - nextsmallerprim;
if(primarray[littleprim]) {
outhelper(innumber, littleprim, nextsmallerprim);
break;
}
else
nextsmallerprim--;

// if( nextsmallerprim <= (innumber/2) ) {
// System.out.println("Goldbach's conjecture is wrong.");
// break;
// }
}

}

}

// just a helpmethod for printing the result
private static void outhelper(int innumber, int smallprim, int bigprim) {
System.out.println(innumber + " = " + smallprim + " + " + bigprim);
}
}