#include<iostream>
using namespace std;

int x[10000000];

void prime(int p) {
	x[2] = 1;
	for (int i = 3; i < p; i += 2) {
		for (int j = 3; j*j <= i; j += 2) {
			if (i%j == 0) { goto E; }
		}
		x[i] = 1;
	E:;
	}
}

int gold(int p) {
	int sum = 0;
	for (int i = 2; i <= p / 2; i++) {
		if (x[i] + x[p - i] == 2) { sum++; }
	}
	return sum;
}

int n;

int main() {
	prime(3000000);
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		cout << gold(n) << endl;
	}
}