class BitSet
  def initialize(size)
    words_size = ((size - 1) >> 6) + 1
    @words = Array.new(words_size, 0)
  end

  def <<(bit_index)
    @words[bit_index >> 6] |= 1 << (bit_index & 63)
  end

  def [](bit_index)
    (@words[bit_index >> 6] & (1 << (bit_index & 63))) != 0
  end
end

def primes_upto(bound)
  f = ->(n) { n % 6 % 5 == 0 ? (n - 2) / 3 : (n / 6) * 2 }
  nbits, limit = f[bound], f[(bound ** 0.5).to_i]
  sieve = BitSet.new(nbits)
  1.upto(limit) do |i|
    if !sieve[i]
      p = i * 3 + (i & 1) + 1
      (p * 2 + i).step(nbits, p * 2).each {|j| sieve << j }
      (p * 2 - i - 1).step(nbits, p * 2).each {|j| sieve << j }
    end
  end
  [2, 3] + (1..nbits).select {|i| !sieve[i] }.map {|x| x * 3 + (x & 1) + 1 }.to_a
end

inputs = []
loop do 
  n = gets.to_i
  break if n == 0
  inputs << n
end 

primes = primes_upto(inputs.max)
inputs.each do |i|
  limit = i / 2
  cnt = 0
  primes.take_while {|x| x <= limit }.each {|p| cnt += 1 if primes.bsearch {|x| (i - p) <=> x } }
  puts cnt
end