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

int main(){
	bool is_prime[1000000]={};
	vector<int> prime;
	for(int i=2;i<1000000;i++){
		if(is_prime[i]) continue;
		prime.push_back(i);
		for(int j=1;i*j<1000000;j++){
			is_prime[i*j] = true;
		}
	}

	int N;
	while(cin>>N,N){
		int ans = 0;
		bool used[1000000] = {};
		for(int i=0; i<prime.size() && prime[i]<N; i++){
			if(used[prime[i]]) continue;
			vector<int>::iterator itr = lower_bound(prime.begin(),prime.end(),N-prime[i]);
			if(itr != prime.end() && prime[i]+*itr == N){
				used[prime[i]] = used[*itr] = true; ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}