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

vector<int> prime;
bool isPrime[1000001];
void primeCalc()
{
	for(int i = 0; i < 1000001; ++i)
	{
		isPrime[i] = true;
	}
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i < 1000001; ++i)
	{
		if(isPrime[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < 1000001; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	primeCalc();
	int n;
	while(cin >> n, n)
	{
		int count = 0;
		int pos = 0;
		while(prime[pos] <= n / 2)
		{
			if(isPrime[n - prime[pos]])
			{
				++count;
			}
			++pos;
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}