#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
using namespace std;
 
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

const int MAX = 1000000;
bool prime[MAX];

void isPrime(){
  fill(prime,prime + MAX,true);
  prime[0] = prime[1] = false;
  rep(i,MAX){
    if(prime[i]){
      for(int j = i + i ; j < MAX ; j += i)
	prime[j] = false;
    }
  }
} 


int main(void){
  isPrime();
  int n ;

  while(cin >> n, n) {
    int ans = 0;
    for(int i = 2; i <= n/2; i++) {
      if(prime[i] && prime[n-i]) ans++;
    }
    cout << ans << endl;
  } 
}