#include <iostream>
using namespace std;

const int LIMIT = 1000001;

int main()
{
	bool* prime = new bool[ LIMIT ]();
	prime[ 0 ] = prime[ 1 ] = true;
	for( int i = 2; i < LIMIT; ++i ){
		if( prime[ i ] ) continue;
		for( int j = i + i; j < LIMIT; j += i ){
			prime[ j ] = true;
		}
	}

	int n;
	while( cin >> n && n ){
		int count = 0;
		for( int i = 0; i < n / 2 + 1; ++i ){
			if( prime[ i ] || prime[ n - i ] ) continue;
			++count;
		}
		cout << count << endl;
	}

	delete[] prime;

	return 0;
}