#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int MAX_N = 1000001;
bool isP[MAX_N];
vector<int> Pri;

int main() {
  {
    fill(isP,isP+MAX_N,true);
    isP[0] = isP[1] = false;
    for(int i = 2; i < MAX_N; ++i) {
      if(!isP[i]) continue;
      Pri.push_back(i);
      for(int j = i*2; j < MAX_N; j += i) isP[j] = false;
    }
  }

  int N;
  while(cin >> N && N) {
    int num = 0;
    for(int i = 0; i < Pri.size() && Pri[i] <= N/2; ++i) {
      if(isP[N-Pri[i]]) ++num;
    }
    cout << num << endl;
  }
  return 0;
}