object Main extends App {
  val src = io.Source.stdin.getLines.map(_.toInt)

  def isPrime(n: Int): Boolean = n > 1 && (2 to math.sqrt(n).toInt).forall(n%_ != 0)

  def findPrimes(count: Int): List[Int] = {
    def loop(num: Int, count: Int): List[Int] = {
      if (count <= 0) Nil
      else if (isPrime(num)) num :: loop(num+1, count-1)
      else loop(num+1, count)
    }

    loop(2, count)
  }

  for (num <- src if num != 0) println(findPrimes(num).sum)
}