#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	bool p[1000000] = {};
	p[0] = p[1] = true;
	rep(i,1001) {
		if(!p[i]) {
			for(int j = 2*i; j<1000000; j+=i) {
				p[j] = true;
			}
		}
	}
	int n;
	while(cin>>n,n) {
		int cnt = 0;
		rep(i,n/2+1) {
			if(!p[i] && !p[n-i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}