
#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);
  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;

  while(scanf("%d", &n)!=EOF) {
    if(n==0)
      break;
    count = 0;
    for(i=0;i<n/2;i++)
      if(!b[i]&&!b[n-i]) count++;
    printf("%d\n", count);
  }
  return 0;
}