#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

#define MAX 1000001

vector<int> vprimes;
bool *isPrime = new bool[MAX];

/* ツ素ツ青板青カツ青ャ O(n^2) */
void MakePrime(){
  isPrime[0]=false;
  isPrime[1]=false;
  isPrime[2]=true;
  for(int i = 2; i < MAX; ++i){
    isPrime[i] = true;
  }
  for(long long int i = 2; i < MAX; ++i){
    if( isPrime[i] ){
      for(long long int j = 2; i * j < MAX; ++j) {
	isPrime[i*j] = false;
      }
    }
  }
  for(int i = 0; i < MAX; ++i){
    if( isPrime[i] ){
      vprimes.push_back( i );
    }
  }
}

int main(){
  MakePrime();
  while(true){
    int n;
    int cnt = 0;
    bool same=false;
    cin >> n;
    if( n == 0 ) break;
    for(int i = 1; i < vprimes.size() && vprimes[i] < n - 2; ++i){
      if( isPrime[ n - vprimes[i] ] ){
	cnt++;
	if( n - vprimes[i] == vprimes[i] ){--cnt;same=true;}
      }
    }
    cnt/=2;
    cout << cnt+same << endl;
  }
  return 0;
}