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);
}
}
}