#include <iostream>
#include <vector>
using namespace std;

const int NMAX=1000000;

int main() {
  bool p[NMAX+1];
  vector<int> pv;
  for (int i=2; i<=NMAX; i++) {
    p[i] = true;
  }
  for (int i=2; i*i<=NMAX; i++) {
    if (!p[i]) continue;
    for (int j=i+i; j<=NMAX; j+=i) {
      p[j] = false;
    }
  }
  for (int i=2; i<=NMAX; i++) {
    if (p[i]) pv.push_back(i);
  }

  int n, ans;
  while (1) {
    cin >> n;
    if (!n) break;
    ans = 0;
    for (int i=0; i<pv.size(); i++) {
      if (pv[i] > n - pv[i]) break;
      if (p[n-pv[i]]) ++ans;
    }
    cout << ans << endl;
  }

  return 0;
}