#include <iostream>
using namespace std;
int main(){
	int n,a,b;
	bool primes[1000001];
        primes[2] = true;
        for (int i = 3; i < 1000001; i += 2) {
                primes[i] = true;
        }
        for (int i = 3; i * i < 1000001; i += 2) {
                if (primes[i]) {
                for (int j = i * 2; j < 1000001; j += i) {
                 primes[j] = false;
                 }
            }
        }
	while(true){
		int cnt=0;
		cin >> n;
		b=n/2;
		if(n==0) break;
		for(int i=0;i<b+1;i++){
			if(primes[i]==true){
				a=n-i;
				if(primes[a]==true){
					cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}