#include<algorithm>
#include<iostream>
#include<vector>

bool isprime[1000001];
std::vector<int> primes;

void sieve()
{
	std::fill( isprime + 2, isprime + 1000001, true );

	for( int i = 2; i <= 1000000; ++i )
	{
		if( isprime[i] )
		{
			primes.push_back( i );

			for( int j = i * 2; j <= 1000000; j += i )
				isprime[j] = false;
		}
	}
}

int main()
{
	sieve();

	int n;
	while( std::cin >> n, n )
	{
		int ans = 0;

		for( int i = 0; i != primes.size() && primes[i] <= n / 2; ++i )
			if( isprime[n - primes[i]] )
				++ans;

		std::cout << ans << std::endl;
	}

	return 0;
}