#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

const int MAX_N = 1000002;
int n;
vector<int> prime(1,2);
bool sieve[MAX_N];

int solve() {
  const int half = *lower_bound(prime.begin(), prime.end(), n/2);
  int ans = 0;
  for (int i = 0; i < prime.size(); ++i) {
    if (half < prime[i]) break;
    const int value = n - prime[i];
    if (binary_search(prime.begin(), prime.end(), value)) ans++;
  }
  return ans;
}

int main() {
  fill(sieve, sieve + MAX_N, true);
  sieve[0] = sieve[1] = false;
  for (int i = 4; i < MAX_N; i+=2) sieve[i] = false;
  for (int i = 3; i < MAX_N; i+=2) if (sieve[i]) {
    prime.push_back(i);
    for (int j = i + i; j < MAX_N; j+=i) sieve[j] = false;
  }
  while (cin >> n, n) {
    cout << solve() << endl;
  }
  return 0;
}