#include <iostream>
using namespace std;

int main(){
  int m[1000001]={},j,a,h,t,cou;
  m[2]=1;
  for(int i=3;i<=1000000;i+=2){
    for(j=3;j*j<=i;j++){
      if(i%j==0)break;
    }
    if(j*j>i)m[i]=1;
  }
  while(1){
    cin >> a;
    if(a==0)break;
    h=0;
    cou=0;
    while(1){
      for(h++;m[h]!=1&&h<=a;h++);
      if(h>a/2)break;
      if(m[a-h]==1)cou++;
    }
    cout << cou << endl;
  }
  return 0;
}