#include<bits/stdc++.h>
using namespace std;

int main() {
  int n;
  int prime[1000000] = {0};
  prime[0] = prime[1] = 1;
  while( cin >> n, n ) {
    for(int i=2; i<=sqrt(n); i++) {
      for(int j=i*2; j<=n; j+=i) {
	prime[j] = 1;
      }
    }
    
    int cnt = 0;
    for(int i=0; i<=n/2; i++) {
      if( !prime[i] && !prime[n-i] ) cnt++;
    }
    
    cout << cnt << endl;
  } 
}