#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

#define MAX 1000000
vector<bool> prime(MAX+1,true);
void init(){
	prime[0] = prime[1] = 0;
	for(int i=2;i*i<=MAX;i++){
		if(prime[i]){
			for(int j=i*i;j<=MAX;j+=i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	init();
	
	int n;
	while(cin >> n , n){
		int ans = 0;
		for(int i=1;i<=n/2;i++){
			if(prime[i] & prime[n-i])ans++;
		}
		cout << ans << endl;
	}
}