#include <iostream>

using namespace std;

int main() {
  int data[50000] = {};
  int size = sizeof(data) / sizeof(int);

  for (int i = 2; i < size; ++i)
    for (int j = i*2; j < size; j+=i)
      data[j] = 1;

  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    int cnt = 0;
    for (int i = 2, i2 = n - 2; i <= i2; ++i, --i2)
      if ((data[i] == 0) && (data[i2] == 0))
        ++cnt;
    cout << cnt << endl;
  }
}
