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

#define MAX 1000001

int main(){
  bool p[MAX];
  memset(p, 1, sizeof(p));
  p[1] = p[0] = 0;
  for(int i = 0 ; i < MAX ; i++){
    if(p[i]){
      for(int j = 2 * i ; j < MAX ; j += i){
	p[j] = 0;
      }
    }
  }

  int n, sum;
  while(cin >> n, n){
    int cnt = 0;
    for(int i = 0 ; i <= n/2 ; i++){
      if(p[i] == 1 && p[n - i] == 1) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}