#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

#define MAX (1000000 / 2) + 100

int main(void)
{
	bool p[MAX];
	for (int i = 3; i < MAX; i++){
		if (i % 2 == 0) p[i] = false;
		else p[i] = true;
	}
	p[0] = p[1] = false;
	p[2] = true;
	for (int i = 3; i < MAX; i += 2){
		if (p[i]){
			for (int j = i * 2; j < MAX; j += i){
				p[j] = false;
			}
		}
	}
	
	int n;
	while (cin >> n, n){
		int res = 0;
		for (int i = 2; i <= n / 2; i++){
			if (p[i] && p[n - i]) res++;
		}
		cout << res << endl;
	}
	
	return 0;
}