#include <bits/stdc++.h>

using namespace std;

int PrimeNumber[1000001] = {0,0,1,1};

void findPrimeNumber(){
	int limit;
	bool flag;

	for (int i = 5; i < 1000001; i += 2) {
		limit = sqrt(i) + 1;
		flag = true;
		for (int j = 2; j < limit; j++) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			PrimeNumber[i] = 1;
		}
	}

	return;
}

int main() {
	int n, rest, sum;

	findPrimeNumber();
	while (cin >> n, n) {
		sum = 0;
		for (int i = 2; i < n; i++) {
			rest = n - i;
			if (i > rest) {
				break;
			}
			if (PrimeNumber[i] == 1 && PrimeNumber[rest] == 1) {
				sum++;
			}
		}
		 
		cout << sum << endl;
	}
	

	return 0;
}
