import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	immutable MAX = 1000000;

	bool p[MAX];
	p[] = 1;
	p[0..2] = 0;
	foreach (i; 2..sqrt(MAX*1.0).ceil.to!int) {
		if (p[i]) {
			foreach (j; iota(i*2, MAX, i))
				p[j] = 0;
		}
	}
	int[] plist;
	foreach (i; 0..MAX) {
		if (p[i]) plist ~= i;
	}

	int n;
	while (n = readln.chomp.to!int, n) {
		int f, b = plist.length - 1, cnt;
		while (f <= b) {
			auto tmp = plist[f] + plist[b];
			if (tmp == n) {
				cnt++;
				f++;
				b--;
			}else if (tmp < n) {
				f++;
			} else {
				b--;
			}
		}
		cnt.writeln;
	}
}