import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {
  val prime = primes(1000000)
  loop()
  @tailrec def loop(): Unit = {
    val n = readInt()
    if (n == 0) return
    println((0 until upperBound(prime, n / 2)).count(p ⇒ binarySearch(prime, n - prime(p))))
    loop()
  }
  def upperBound(array: Array[Int], target: Int): Int = {
    var left = 0
    var right = array.length
    while(left < right) {
      val mid = (left + right) / 2
      if (array(mid) <= target) left = mid + 1
      else right = mid
    }
    right
  }
  def binarySearch(array: Array[Int], target: Int): Boolean = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (array(mid) < target) left = mid + 1
      else right = mid
    }
    right < array.length && array(right) == target
  }
  def primes(upperLimit: Int): Array[Int] = {
    val isPrime = Array.fill(upperLimit + 1){true}
    for (i ← 2 to math.sqrt(upperLimit).ceil.toInt if isPrime(i); j ← i * i to upperLimit by i) {
        isPrime(j) = false
    }
    (2 to upperLimit).filter(isPrime).toArray
  }
}
