prime = Array.new(50001, true)
for i in 2..50000 ** 0.5
  if prime[i]
    for j in 2..50000 / i
      prime[i * j] = false
    end
  end
end
prime[0], prime[1] = false, false
while (n = gets.to_i) != 0
  sum = 0
  if n % 2 == 0
    for i in 1..n / 4
      if prime[2 * i + 1] and prime[n - 2 * i - 1]
        sum += 1
      end
    end
  elsif prime[n - 2]
    sum += 1
  end
  puts sum
end