#include <iostream>
#include <vector>

using namespace std;

int main() {
	vector<int> furui(1000010, 0);
	furui[0] = furui[1] = 1;
	for (int i = 2; i * i < 1000010; i++) {
		if (furui[i] == 0) {
			for (int j = 2; j <= 1000010 / i; j++) {
				furui[i*j] = 1;
			}
		}
	}
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int counter = 0;
		for (int i = 3; i <= n/2; i+=2) {
			if (furui[i] == 0) {
				if (furui[n-i] == 0) {
					counter++;
				}
			}
		}
		cout << counter << endl;
	}
	return 0;
}