#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

bool sieve[1000001];
vector<UL> P;

int main() {
	rep(i, 1000001) sieve[i] = true;
	sieve[0] = sieve[1] = false;
	for (UL p = 2; p <= 1000000; p++) {
		if (!sieve[p]) continue;
		P.push_back(p);
		if (p <= 1000) for (UL j = p * p; j <= 1000000; j += p)
			sieve[j] = false;
	}

	UL N;
	while (true) {
		cin >> N;
		if (N == 0) break;
		UL ans = 0;
		rep(i, P.size()) {
			UL p = P[i];
			if (p + p > N) break;
			if (sieve[N - p]) ans++;
		}
		cout << ans << "\n";
	}
	cout << flush;

	return 0;
}

