#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
#define sz(c) int((c).size())

vector<bool> primes(50100, true);
void build () {
  primes[0] = false;
  primes[1] = false;
  for (int i = 2; 2*i < sz(primes); i++) {
    primes[2*i] = false;
  }
  for (int i = 3; i*i <= sz(primes); i+=2) {
    if (primes[i]) {
      for (int j = 2; i*j < sz(primes); j++) {
        primes[i*j] = false;
      }
    }
  }
}

int gbc(int n)
{
  int res = 0;
  if (primes[n-2])
    res++;
  for (int i = 3; 2*i <= n; i+=2) {
    if (primes[n-i])
      res++;
  }
  return res;
}

int main(int argc, char **argv)
{
  int n;
  build();
  while (cin >> n) {
    if (!n)
      break;
    cout << gbc(n) << endl;
  }
  return 0;
}