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

const int MAX = 1000000;
int notp[MAX + 1];

void prime(){
	notp[0] = 1;
	notp[1] = 1;
	
	for(int i = 2; i <= MAX; ++i){
		int j = i * 2;
		while(j <= MAX){
			notp[j] = 1;
			j += i;
		}
	}
}

int main(){
	int n, c;
	prime();
	
	while(c = 0, cin >> n, n){
		for(int i = 3; i <= n / 2; ++i){
			if(notp[i] == 0 && notp[n - i] == 0) ++c;
		}
		cout << c << endl;
	}
	
	return 0;
}