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

long long int a[1000000] = {0},n;

int main(){

  for(int i=2;i*i<=1000000;i++){
    if(a[i] == 0){
      for(int j=i+i;j<=1000000;j+=i) a[j] = 1;
    }
  }

  while(cin >> n, n){

    int ans = 0;

    for(int i=2;i<=n/2;i++){
      if(a[i] == 0 && a[n - i] == 0) ans++;
    }

    cout << ans << endl;

  }
}