#include <iostream>
#include <cmath>
using namespace std;

int p[78500],flg[1000004],size;

bool isPrime(int x){
	for(int i=0;i<size && p[i]<=sqrt(x);i++){
		if(x % p[i] == 0) return false;
	}
	return true;
}

void mkPrime(void){
	p[0] = 2;
	flg[2] = size = 1;

	for(int i=3;i<=1000000;i+=2){
		if(isPrime(i)){
			p[size++] = i;
			flg[i] = 1;
		}
	}
}

int main(void){
	int x;

	mkPrime();

	while(cin>>x && x){
		int ans = 0, to = x / 2;
		for(int i=0;p[i]<=to;i++){
			if(flg[x-p[i]]) ans++;
		}
		cout<<ans<<endl;
	}

	return 0;
}