#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

bool prime[1000002];

void seive(int s){
	for(int i=0;i<=s;i++)prime[i]=true;
	prime[0]=prime[1]=false;
	for(int i=2;i<=s;i++){
		if(prime[i]==true){
			for(int j=i*2;j<=s;j+=i)prime[j]=false;
		}
	}
}

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