#include<stdio.h>
int prime[1000001];
int main(){
	prime[0]=prime[1]=-1;
	for(int i=2;i<=1000000;i++){
		if(prime[i]!=-1){
			prime[i]=1;
			for(int j=i+i;j<=1000000;j+=i)prime[j]=-1;
		}
	}
	int a;
	while(scanf("%d",&a),a){
		int ret=0;
		for(int i=1;i<=a/2;i++)if(prime[i]==1&&prime[a-i]==1)ret++;
		printf("%d\n",ret);
	}
}