#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, c, p=0;
	bool pr[1000001];
	fill(pr, pr+1000001, true);
	pr[0] = pr[1] = false;
	
	for(int i = 2; i < 1000001; i++){
		if(pr[i]){
			for(int j = 2*i; j < 1000001; j+=i){
				pr[j] = false;
			}
		}
	}

	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		c = 0;
		for(int i = 2; i <= n/2; i++){
			if(pr[i]){
				if(pr[n-i]){
					c++;
				}
			}
		}
		cout << c << endl;
	}
	
	return 0;
}