
object Main {

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

    source.map(_.toInt).filter(_ != 0).foreach { n =>
      val useCoins: List[Int] = coins.takeWhile(_ <= n).reverse.toList

      val result = pay_num(n, useCoins)

      println(result)
    }
  }


  lazy val coins: Stream[Int] = Stream.from(1).map(p => p * p)

  def pay_num(n: Int, useCoins: List[Int]): Int = {
    if (n == 0 || useCoins.size <= 1) {
      1
    } else {
      val x = useCoins.head
      (0 to n / x).fold(0) {(sum, i) => sum + pay_num(n - (i * x), useCoins.tail)}
    }
  }
}