#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
using namespace std;
int sosu[1000001];
vector<int> s;
int N;
int main(){
  for(int i=2;i<1000000;i++){
    if(sosu[i]) continue;
    s.push_back(i);
    for(int j=i+i;j<1000000;j+=i){
      sosu[j]=1;
    }
  }
  while(scanf("%d",&N),N){
    int res = 0;
    for(int i=0;i<=(int)s.size();i++){
      int h = N - s[i];
      //    printf("%d %d\n",s[i],h);
      if(h<0) break;
      if(h<s[i]) break;
      if(!sosu[h]) res ++;
    }
    printf("%d\n",res);
  }
}