#include <bits/stdc++.h>
using namespace std;

bool p[1010101];

int main()
{
  memset(p, true, sizeof(p));

  p[0] = p[1] = false;

  for (int i = 0; i < 1001; i++){
    if (!p[i]) continue;
    for (int j = 2 * i; j < 1000000; j += i){
      p[j] = false;
    }
  }

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