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

#define MAX 1000000

int main( void )
{
	// ツ素ツ青板表ツづーツ催ャツ青ャツつキツづゥ
	vector <bool> is_prime( MAX + 1, false );
	is_prime[2] = 0;
	for ( int i = 3; i < MAX + 1; i += 2 )
		is_prime[i] = true;
	for ( int i = 3; i < MAX + 1; i += 2 )
	{
		if ( is_prime[i] )
		{
			for ( int j = i + i; j < MAX + 1; j += i )
				is_prime[j] = false;
		}
	}

	int n;
	while ( cin >> n && n > 0 )
	{
		int cnt = 0;
		if ( is_prime[n-2] )
			cnt++;
		for ( int i = 3; i <= n / 2; i += 2 )
		{
			if ( is_prime[i] && is_prime[n-i] )
				cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}