#include<iostream>
using namespace std;
bool prime[1000000];
int main(){
	for(int i = 2; i * i <= 1000000; i++){
		if(prime[i] == 0){
			for(int j = i; j <= 1000000; j+=i){
				prime[j] = 1;
			}
			prime[i] = 0;
		}
	}
	int n;
	while(cin >> n,n){
		int cnt = 0;
		for(int i = 2; i <= n/2; i++){
			if(prime[i])continue;
			else {
				if(!prime[n-i])cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}