#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, primes[100000], prime_sz = -1;
bool used[100000];
bool sieve[MAX_N];


int solve() {
  int ans = 0;
  fill(used, used + 100000, false);

  for (int i = 0; i < prime_sz; ++i) {
    if (used[i]) continue;
    const int value = n - primes[i];
    const int vl = lower_bound(primes, primes + prime_sz, value) - primes;
    if (used[vl]) continue;
    if (n != primes[i] + primes[vl]) continue;
    used[i] = used[vl] = true;
    ans++;
  }
  return ans;
}

int main() {
  // prime
  primes[0] = 2;
  int cnt = 1;
  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]) {
    primes[cnt] = i; cnt++;
    for (int j = i + i; j < MAX_N; j+=i) sieve[j] = false;
  }
  prime_sz = cnt;
  
  while (cin >> n, n) {
    cout << solve() << endl;
  }
  return 0;
}