#include<iostream>
#include<string.h>
using namespace std;

int isprime[1000001] = { 0 };

int main() {

  isprime[1]=1;
  for(int i=4; i<1000001; i+=2)
    isprime[i] = 1;

  for(int i=3; i<1000001; i++) {
    if(isprime[i] == 0)
      for(int j=2; i*j<1000001; j++)
	isprime[i*j] = 1;
  }

  int n;

  while(true) {
    cin>>n;
    if(!n) break;

    int res=0;
    for(int i=2; i<n/2+1; i++)
      if( (isprime[i] == 0) && (isprime[n-i] == 0) ) {
	//cout<<i<<"+"<<n-i<<"="<<n<<endl;
	res++;
      }

    cout<<res<<endl;
  }
}