import std.stdio;
import std.string, std.conv;
import std.algorithm, std.array;
import std.typecons;

void main() {
  const int P_MAX = 500000;

  bool[] isp = new bool[P_MAX + 1];
  isp[] = true;
  isp[0] = isp[1] = false;
  for(int i = 2; i * i <= P_MAX; i++) {
    if(isp[i]) {
      for(int j = 2 * i; j <= P_MAX; j += i)
        isp[j] = false;
    }
  }

  bool[int] set;
  foreach(i; 2 .. P_MAX + 1)
    if(isp[i])
      set[i] = true;

  for(int N; N = readln.chomp.to!int, N; ) {
    int s = 0;
    foreach(i; set.keys) {
      if(i > N) continue;
      int rest = N - i;
      if(i <= rest) {
        if((rest in set) != null) s++;
      }
    }
    writeln(s);
  }
}