#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
int cnt[7];
int main(){
    int i,j,n,prime[1000001];
    prime[0]=prime[1]=-1;
    for(i=2;i<=1000000;i++){
        if(prime[i]!=-1){
            prime[i]=1;
            for(j=i+i;j<=1000000;j+=i)prime[j]=-1;
        }
    }
    while(cin>>n,n){
        int cnt=0;
        for(i=1;i<=n/2;i++){
            if(prime[i]==1&&prime[n-i]==1) cnt++;
        }
        cout<<cnt<<endl;
        }
    return 0;
}
