#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

vector<int> eratosthenes(int n) {
  vector<int> v(n);
  for (int i=2; i<n; i++) v[i] = i;
  for (int i=2; i*i<n; i++)
    if (v[i])
      for (int j=i*i; j<n; j+=i)
        v[j] = 0;
//  v.erase(remove(ALL(v),0),v.end()); // ツつアツつアツづーツづつつッツづェツづ篠素ツ青板δ環スツト
  return v;
}

int main() {
  vector<int> table = eratosthenes(1000000);
  vector<int> prime = table;
  prime.erase(remove(ALL(prime),0),prime.end()); // ツつアツつアツづーツづつつッツづェツづ篠素ツ青板δ環スツト
 
  int n;
  while(cin >> n, n) {
    int res = 0;
    for (int i=0; prime[i] <= n/2; ++i) {
      if (table[n - prime[i]])
        res++;
    }
    cout << res << endl;
  }
}