#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
using namespace std;

const int INF = 1e9;
typedef long long ll;
#define MAX_N 1000001

int n;
bool isPrime[MAX_N];

void init(){
  for(int i = 0; i <= MAX_N; i++) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i * i <= MAX_N; i++){
    if(isPrime[i]) for(int j = i * i; j <= MAX_N; j += i){
      isPrime[j] = false;
    }
  }
}

int main(void){
  init();
  while(cin >> n && n){
    int cnt = 0;
    for(int i = 2; i < n; i++){
      if(i <= n / 2 && isPrime[i] && isPrime[n-i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}