
object Main1200 {

  def main(args: Array[String]) {
    val source = scala.io.Source.stdin.getLines.toSeq

    source.filter(_ != "0").foreach {s =>
      val target = s.toInt

      val primeList: List[Int] = primes.takeWhile( _ <= target ).toList

      val result: Int = (for {
        p <- primeList.filter(p => p <= target / 2)
        if (primeList.contains(target - p))
      } yield p).size

      println(result)
    }
  }

  lazy val primes: Stream[Int] = {
    def isPrime(i: Int): Boolean =
      primes takeWhile {Math.sqrt(i) >= _} forall {i % _ != 0}

    2 #:: 3 #:: (Stream.from(2)).map{_ * 2 + 1}.filter{ isPrime(_) }
  }

}