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

int sosu[500000];
int scmax,sosumi;

void setsosu(int n){
  int flg,j;
  if (n<scmax) return;
  for (int i=scmax+1;i<=n;i++){
    flg=0;
    for (j=sosu[0];j<=sqrt(i);j++){
      //cout << i << " " << j << " " << i%j << endl;
      if (i%j==0){flg =1;break;}
    }
    if (flg==0) sosu[++sosumi]=i;
  }
  scmax =n;
}
int nibutan(int n){
  int l,r,m;
  l=0;
  r=sosumi+1;
  while (l<r){
    m=(l+r)/2;
    if (sosu[m]>n){
      r=m;
    }else if (sosu[m]<n){
      l=m+1;
    }else{
      return 1;
    }
  }
  return 0;
}
int main(){
  int n,ret;
  sosu[0]=2;
  sosu[1]=3;
  sosu[2]=5;
  sosu[3]=7;

  scmax=7;
  sosumi=3;

  while (1){
    cin >> n;
    if (n==0) break;
    ret =0;
    setsosu(n);
    for (int i=sosu[1];i<=n/2;i+=2){
      if (nibutan(i)==1&&nibutan(n-i)==1) {
	ret++;
	//cout << i <<" "<< n-i << endl;

      }
    }
    cout << ret << endl;
  }
  return 0;
}