1.

package sem2.am.goldbachsconjecture2;

/**
* Angewandte Mathematik, SS11
* Problem: 686 - Goldbach's Conjecture 2
* Link: http://uva.onlinejudge.org/external/6/686.pdf
*
* @author Florian Stein
* @author Franz Sommer
* @version 1.0, 03/30/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.228
*/

import java.util.*;

class Main {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();

// Abbruchschleife
if (n == 0)
break;

int found = 0;

// Vergleich entgegengesetzt abfragen
for (int j = 0; j <= n/2; j++) {
if (n < 1000000 && n >= 4 && n != 0) {
if (prime(j) && prime(n - j)) {
found++;
}
}
}
System.out.println(found);
}
}

// Entscheidet ob Zahl eine Primzahl
public static boolean prime(int n) {
if (n < 2)
return false;
if (n == 2)
return true;
if ((n % 2) == 0)
return false;
for (int i = 3; i <= Math.sqrt(n); i += 2) // i = i+2
{
if (n % i == 0)
return false;
}
return true;
}
}

2.

/**
* Angewandte Mathematik, SS11
* Problem: 543 - Goldbachs Conjecture
* http://uva.onlinejudge.org/external/6/686.pdf
* @author Sebastian Stumpf
* @author Benjamin Vogt
* @version 1.0, 2011-03-31 08:54:40
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.244
*/

import java.util.Scanner;

public class Main
{
public boolean[] ErastoPrimes(int n)
{
boolean[] ausgesiebt = new boolean[n];
// long start = System.currentTimeMillis();
for(int i = 0; i < n ; i++)
{
ausgesiebt[i] = false; //vorbelegung mit "nicht ausgesiebt"
}
// System.out.println("init ausgesiebt[]: (ms) "+(System.currentTimeMillis() - start));

// long start2 = System.currentTimeMillis();
for(int i = 2; i < n; i++)
{
//wenn nicht ausgesiebt => primzahl => addTo ArrayList
if(ausgesiebt[i] == false)
{
// primSet.add(i);
//alle vielfachen der vorher als primzahl erkannten zahl aussieben
for(int j = 2; i*j < n; j++)
{
ausgesiebt[i*j] = true;
}
}
}
// System.out.println("create ausgesiebt[] und primSet: (ms) "+(System.currentTimeMillis() - start2));
return ausgesiebt;
}

public static void main(String[] args)
{
//Test DataSheet
/* StringBuilder sb = new StringBuilder("");
for(int i=6; i<=100000; i+=2)
{
sb = sb.append(i+(i%50 == 0? "\n": " "));
}
sb.append("0");
String s = sb.toString();
*/
Main a = new Main();
// long start = System.currentTimeMillis();
boolean[] primzahlen = a.ErastoPrimes(32768);
// System.out.println("create PrimeHashSet: (ms) "+(System.currentTimeMillis() - start));

Scanner scanner = new Scanner(System.in);
int zahl;

// start = System.currentTimeMillis();
while((zahl = scanner.nextInt()) != 0)
{
if(zahl < 4 || zahl%2 != 0)
break;
int count = 0;
for(int i = 2; i <= zahl/2; i++)
{

if(!primzahlen[i] && !primzahlen[zahl-i])
{
count++;
}
}
System.out.println(count);
}
// System.out.println("Algorithmus: (ms)"+(System.currentTimeMillis() - start));

}
}

3.

/**
* Angewandte Mathematik, SS11
* Problem: 686 Goldbach's Conjecture
* Link: http://uva.onlinejudge.org/external/5/543.pdf
*
* @author Ritter Marius
* @author Wende Tom
* @author Zehentbauer Stefan
* @version 1.0, 04/04/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.204
*/

import java.util.Scanner;

public class Main {

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


public static void main(String args[])
{
Scanner eingabe1 = new Scanner(System.in);
do
{
int x = eingabe1.nextInt();
if(x==0)
break;
int count = 0;
for (int i=2; i<x; i++) // und ausgegeben
{
if(isPrime(i))
{
for(int y=(x-i); y>=i;y--)
{
if(isPrime(y))
{
if((x==(i+y)))
{
count++;
break;
}
else if(((i+y)<x))
{
break;
}
}
}
}
}
System.out.println(count);
}while(true);
}

}

4.

/**
* Angewandte Mathematik, SS11
* Problem: 686 Goldbach's Conjecture
* Link: http://uva.onlinejudge.org/external/5/543.pdf
*
* @author Ritter Marius
* @author Wende Tom
* @author Zehentbauer Stefan
* @version 2.0, 04/04/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.180
*/

import java.util.Scanner;

public class Main {

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


public static void main(String args[])
{
Scanner eingabe1 = new Scanner(System.in);
do
{
int x = eingabe1.nextInt();
if(x==0)
break;
int count = 0;
for (int i=2; i<=x/2; i++)
{
if(isPrime(i))
{
for(int y=(x-i); y>=i;y--)
{
if(isPrime(y))
{
if((x==(i+y)))
{
count++;
break;
}
else if(((i+y)<x))
{
break;
}
}
}
}
}
System.out.println(count);
}while(true);
}

}

5.

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
* Angewandte Mathematik, SS11
* Problem: 686 - Goldbach's Conjecture II
* Link: http://uva.onlinejudge.org/external/5/543.pdf
*
* @author Benedikt Z¨nnchen
* @author Erik Wenzel
* @version 1.0, 03/29/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.176
*/

public class Main
{
private static Set<Integer> set = new HashSet<Integer>();

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int number;
int result;

while((number = sc.nextInt()) != 0)
{
result = 0;
if(isPrime(2) && isPrime(number-2))
{
result++;
}
for(int i = 1; i <= number/2; i+=2)
{
if(isPrime(i) && isPrime(number-i))
{
result++;
}
}
System.out.println(result);
}
}

/**
* Bestimmt ob eine ganze Zahl eine Primzahl ist. (schleifen-l¨sung)
* @param n ganze zahl
* @return true wenn n eine Primzahl ist, sonst false
*/
public static boolean isPrime(int n)
{
if(n == 2)
{
set.add(n);
return true;
}
else if(n < 2 || n%2==0)
{
return false;
}
else if(set.contains(n))
{
return true;
}
for(int i = 3; i <= Math.sqrt(n); i+=2)
{
if(n%i==0)
{
return false;
}
}
set.add(n);
return true;
}
}


----------------------------------------------
1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 686 Golbach's Conjecture (II)
* Link: http://uva.onlinejudge.org/external/6/686.pdf
*
* @author Anton Pavlushko, IBB7B,
* @version 1.0, 10/10/2010
*
* Status : Accepted
* Runtime: 2.020
*/

import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String current_line;
Vector all_primes = new Vector();
all_primes.add(2);
all_primes.add(3);
all_primes.add(5);
all_primes.add(7);
int maximum, current_element;
maximum = 0;
int count_pairs = 0;
int left, right, counter, prime_candidate;
double counter_border, counter_int;
boolean prime;

try {
while ((current_line=in.readLine())!= null && !current_line.equals("0")) {
current_element = Integer.parseInt(current_line);

if (current_element>maximum) {
left = maximum/6;
right = current_element/6;

maximum=current_element;

for(counter=left;counter<=right;counter++) {
prime_candidate=6*counter-1;
counter_border=Math.sqrt(prime_candidate)+1;
prime=true;
for(counter_int=3;counter_int<counter_border;counter_int=counter_int+2) {
if (prime_candidate%counter_int==0) {
prime=false;
break;
}
}

if (prime && !all_primes.contains(prime_candidate))
all_primes.add(prime_candidate);

prime_candidate=6*counter+1;
prime=true;
for(counter_int=3;counter_int<counter_border;counter_int=counter_int+2) {
if (prime_candidate%counter_int==0) {
prime=false;
break;
}
}

if (prime && !all_primes.contains(prime_candidate))
all_primes.add(prime_candidate);
}
}//add new primes

count_pairs=0;
right=current_element/2;
for(left = 2;left<=right;left++) {
if (all_primes.contains(left) &&
all_primes.contains(current_element-left)) {
count_pairs++;
}
}

System.out.println(count_pairs);

} // end while
} // end try
catch (IOException e) {
System.err.println("Error: " + e);
}
}
}