#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

vector<int> sieve(int n) {
	vector<int> res(1, 2);
	vector<bool> prime(n, true);
	for(int i = 3; i < n; i += 2) {
		if(prime[i]) {
			res.push_back(i);
			for(int j = i * 3; j < n; j += i * 2)
				prime[j] = false;
		}
	}

	return res;
}

int main() {
	const int MAX = 1000000;
	vector<int> prime = sieve(MAX);

	for(int n; scanf("%d", &n), n;) {
		int ans = 0;
		for(int i = 0, j = prime.size() - 1; i < prime.size(); ++i) {
			while(j >= 0 && prime[i] + prime[j] > n) --j;

   			if(prime[i] + prime[j] == n) {
				ans += 1 + (i == j);
				--j;
			}
		}

   		printf("%d\n", ans / 2);
	}

	return EXIT_SUCCESS;
}