#include<iostream>
using namespace std;
bool a[1000001];
int main() {
	fill(a, a + 1000001, true);
	a[0] = false;
	a[1] = false;
	for (int i = 2; i <= 1000000;) {
		if (a[i]) {
			int j = 2;
			while (i*j <= 1000000) {
				a[i*j] = false;
				j++;
			}
		}
		if (i % 2 == 0)i++;
		else i += 2;
	}
	int n;
	while (cin >> n&&n != 0) {
		int sum = 0;
		if (a[n - 2]) sum++;
		for (int i = 3; i <= n / 2 ; i+=2) {
			if (a[i] && a[n - i]) sum++;
		}
		cout << sum << endl;
	}
}