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

#define MAX 1000000
#define sqrtMAX sqrt(MAX)

int main(void)
{
  int n;
  vector<int> b(MAX+1);
  vector<int> p(MAX+1);
  vector<int> c(MAX+1);
  int i, j;
  int count;

  // ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
  b[0] = 1;
  b[1] = 1;
  for(i=4; i<=MAX; i+=2)
      b[i] = 1;
  for(i=3; i<sqrtMAX; i+=2)
      for(j=i+i; j<=MAX; j+=i)
          b[j] = 1;

  // ツ素ツ青板づーツ板イツつォツ出ツつキ
  count = 0;
  for(i=0; i<=MAX; i++) {
    if(b[i])
      continue;
    p[count++] = i;
  }

  for(i=0; i<count; i++) {
    for(j=i; j<count; j++) {
      if(p[i]+p[j] > MAX)
        break;
      c[p[i]+p[j]]++;
    }
  }

  while(scanf("%d", &n)!=EOF) {
    if(n==0)
      break;
    printf("%d\n", c[n]);
  }
  return 0;
}