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

vector<int>primes(1000001);
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	vector<int>sos;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
	for (int i = 0; i <= amax; ++i) {
		if (sos[i]) {
			primes[i] = true;
		}
	}
	flag = true;
}

int main() {
	hurui(1000000);
	while (1) {
		int N; cin >> N;
		if (!N)break;
		int ans = 0;
		for (int i = 2; i <= N / 2; ++i) {
			if (primes[i] && primes[N - i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}