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

int main(){
	bool prime[1000001] = {true,true};
	vector<int> ps;
	for(int i = 4;i <= 1000000;i += 2) prime[i] = true;
	for(int i = 3;i * i <= 1000000;i += 2){
		for(int j = i * 2;j <= 1000000;j += i) prime[j] = true;
	}
	for(int i = 0;i <= 1000000;i++) if(!prime[i]) ps.push_back(i);
	int n;
	while(cin >> n,n){
		int cnt = 0;
		for(int i = 0;i < ps.size();i++){
			if(ps[i] > n / 2) break;
			if(find(ps.begin(),ps.end(),n - ps[i]) != ps.end()) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}