1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: 686 Goldbach's Conjecture (II)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=8&problem=627&mosmsg=Submission+received+with+ID+7481793
*
* @author Stefan Gohlke
* @version 1.0, 10/14/2009
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.532
*/

package golbach2_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);
long n = 0;
long[] gefundeneZahlen;
int gefundeneZahlenCounter;
long treffercounter = 0;
n = scanner.nextLong();

while (n != 0)
{
gefundeneZahlen = new long[32768];
gefundeneZahlenCounter=0;

if (n%2==0 && n >=4 && n < 32768)
{
//höchste Primzahl nach n ermitteln
long naechsthoechstePrim = n;
boolean istPrim= false;
while (!istPrim)
{
naechsthoechstePrim--;
if (naechsthoechstePrim ==2) istPrim= true;
else if (!istVorhanden(naechsthoechstePrim, gefundeneZahlen, gefundeneZahlenCounter) && pruefPrim(naechsthoechstePrim))
{
long a = n-naechsthoechstePrim;
if (!istVorhanden(a, gefundeneZahlen, gefundeneZahlenCounter) && a > 1 && pruefPrim(a))
{
gefundeneZahlenCounter++;
gefundeneZahlen[gefundeneZahlenCounter]= naechsthoechstePrim;
gefundeneZahlenCounter++;
gefundeneZahlen[gefundeneZahlenCounter]= a;

treffercounter++;
}
}
}
if (n==4)
{
System.out.println("1");
}
else
{
System.out.println(treffercounter);
}

treffercounter=0;
gefundeneZahlen = null;
gefundeneZahlenCounter = 0;
}


n = scanner.nextLong();
}
}

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

public static boolean istVorhanden(long zuPruefendeZahl, long[] gefundeneZahlen, int schonEingetragen)
{
for (int i = 0; i < schonEingetragen; i++)
{
if (zuPruefendeZahl == gefundeneZahlen[i]) return true;
}
return false;
}
}

2.

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


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

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

// number should be less than this number
int maxin = (int) java.lang.Math.pow(2, 15);
// 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++;
}

// 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 4 <= 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;

// Variable for counting the possibilities
int possibilities = 0;
// limit is to exclude doubles in search like 13 + 5 = 5 + 13 = 18
int limit = innumber/2;

while(nextsmallerprim >= limit) {
while (!primarray[nextsmallerprim])
nextsmallerprim--;
if(!(nextsmallerprim >= limit))
break;

littleprim = innumber - nextsmallerprim;
if (primarray[littleprim])
possibilities++;
nextsmallerprim--;
}
System.out.println(possibilities);
}

}

}