#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

int p[5000000];

bool prime(int x){
  if(x==2) return false;
  
  if(x<1||x%2==0) return false;

  int i=3;
  while(i<=sqrt(x)){
    if(x%i==0)return false;
    i+=2;
  }
  return true;
}

int main(){
  int n,ans;
 

  int j=0;
  for(int i=3;i<=1000000;i++) if(prime(i)) p[j++]=i;
  while(1){
    ans=0;
    cin>>n;
    if(n==0) break;
    for(int i=0;p[i]<=(n+1)/2;i++){
      if(prime(n-p[i])) ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}