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

bool is_prime[10000001];
vector<int> prime;

void sieve(){
	fill(is_prime,is_prime+10000001,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2; i<=10000000; ++i){
		if(is_prime[i]){
			prime.push_back(i);
			for(int j=2; i*j<=10000000; ++j){
				is_prime[i*j]=false;
			}
		}
	}
}

int main(){
	sieve();
	int N;
	while(cin >> N&&N){
		long long int ans=0;
		for(int i=0; i<=N/2; ++i){
			if(is_prime[i]&&binary_search(prime.begin(),prime.end(),N-i)){
				//cout << i << endl;
				++ans;
			}
		}
		cout << ans << endl;
	}
	return 0;
}