#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_N = 1000001;

vector<int> p;
bool isp[MAX_N];
int ans[MAX_N];

void make_prime(){
  REP(i, MAX_N) isp[i] = true;
  isp[0] = isp[1] = false;
  FOR(i, 2, MAX_N){
    if(!isp[i]) continue;
    p.push_back(i);
    for(int j = i + i; j < MAX_N; j += i) isp[j] = false;
  }
}

int main() {
  make_prime();
  memset(ans, 0, sizeof(ans));
  REP(i, p.size()) FOR(j, i, p.size()) if(p[i] + p[j] < MAX_N) ++ans[p[i] + p[j]];
  int N;
  while(cin >>N && N) cout <<ans[N] <<endl;
  return 0;
}