#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
const int MAX = 1000001;
int main(void){
  bool prime[MAX];
  vector<int> p;
  FOR(i,2,MAX) prime[i]=true;
  FOR(i,2,MAX){
    if(prime[i]){
      p.push_back(i);
      for(int k=2; i*k<=MAX; k++){
        prime[i*k]=false;
      }
    }
  }
  int n;
  while(cin>>n){
    if(n==0) break;
    int count=0;
    for(int i=0; i<p.size()&&2*p[i]<=n; i++){
      if(prime[n-p[i]]) count++;
    }
    cout<<count<<endl;
  }
  return 0;
}