#include<iostream>
using namespace std;
int main(){
long n,c,*p,i,j;
n=1000000;
p=new long[1000001];
for(p[1]=0,i=3;i<=n;i+=2)p[i]=1;
for(p[2]=1,i=4;i<=n;i+=2)p[i]=0;
j=3;
while(j*j<=n){
for(i=j;i<=n/j;i+=2)p[i*j]=0;
j++;
while(p[j]==0)j++;
}
while(cin>>n){
if(n==0)break;
for(c=0,i=3;i*2<=n;i++){
if(p[i]==1&&p[n-i]==1)c++;
}
cout<<c<<endl;
}
return 0;
}