#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[33000]={0,0,1,1},c,i,j;
  for(i=4;i<33000;i++){
    for(j=2,c=1;j*j<=i;j++){
      if(i%j==0)c--;
    }
    if(c>0)a[i]=1;
    else a[i]=0;
  }
  while(cin>>n,n){
    for(i=3,c=0;i<n;){
      for(j=n-1;j>2;){
	if(i+j==n)c++;
	while(!a[--j]);
      }
      while(!a[++i]);
    }
    cout<<(c-1)/2+1<<endl;
  }
}