#include <stdio.h>

#define MAX_NUM (1000000)

char prime[MAX_NUM + 1];

void make_prime()
{
	for (int i = 0; i < MAX_NUM + 1; i++){
		prime[i] = 1;
	}
	prime[0] = prime[1] = 0;
	
	for (int i = 2; i * i < MAX_NUM; i++){
		if (prime[i] == 1){
			for (int j = 2; j * i <= MAX_NUM; j++){
				prime[j * i] = 0;
			}
		}
	}
}

int main(void)
{
	int n;
	int cnt;
	
	make_prime();
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		cnt = 0;
		for (int i = 3; i <= n / 2; i++){
			if (prime[i] == 1 && prime[n - i] == 1){
				cnt++;
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return (0);
}