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

bool p[40000];

void mkP(){
  memset(p, true, sizeof(p));
  p[0] = p[1] = false;

  for(int i = 2; i * i < 40000; i++){
    if(!p[i]) continue;
    for(int j = i + i; j < 40000; j += i){
      p[j] = false;
    }
  }
}

int main(){
  mkP();

  int n;

  while(cin >> n, n){
    int cnt = 0;

    for(int i = 2; i <= n; i++){
      int j = n - i;
      if(i > j) break;
      if(p[i] && p[j]) cnt++;
    }

    cout << cnt << endl;
  }
}