#include <cstdio>
#define MAX 1000001

int a[ MAX ] = {0};

int main( void ){
	int n;
	int counter;
	
	
	for( int i = 2; i <= MAX; i++ ){
		if( a[ i ] ){ continue; }
		for( int j = i * 2; j <= MAX; j += i ){
			a[ j ] = 1;
		}
	}
	
	while(1){
		scanf( "%d", &n ); 
		if(!n){break;}
		counter = 0;
		for( int i = 2; i <= n / 2; i++ ){
			int comp = n - i;
			if( !a[ i ] && !a[ comp ] ){
				counter++;
			}
		}
		printf( "%d\n", counter );
	}
	return 0;
}