#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

int main() {
	bool NonPrime[1000000+1]={0};
	NonPrime[0]=NonPrime[1]=true;
	for(long i=2;i<=1000000;i++){
		if(NonPrime[i]) continue;
		for(long j=2*i;j<=1000000;j+=i) NonPrime[j]=true;
	}
	vector<long> Prime;
	vector<long>::iterator vp;
	for(long i=2;i<=1000000;i++) if(!NonPrime[i]) Prime.push_back(i);
	while(1){
		long n; cin >> n ; if(!n) break;
		long cnt=0;
		for(vp=Prime.begin();vp<Prime.end();vp++){
			if(n-*vp<2 || n-*vp<*vp) break;
			if(!NonPrime[n-*vp]) cnt++;
		}
		cout << cnt << '\n' ;
	}
}