object Solution {
  val moduloP = 1e9.toInt + 7
  val coinSizes = Array(1, 2, 5, 10, 20, 50, 100, 200)

  def countTable(coinSizes: Array[Int], n: Int): Array[Int] = {
    val ways = Array.fill(n + 1)(0)
    ways(0) = 1
    for {i <- 0 until coinSizes.length
         j <- coinSizes(i) to n} {
      ways(j) = (ways(j) + ways(j - coinSizes(i))) % moduloP
    }
    ways
  }

  def main(args: Array[String]) {
    val t = readLine.toInt
    val testCases = (1 to t).map(x => readLine.toInt)
    val n = testCases.max
    val table = countTable(coinSizes, n)
    testCases foreach { x =>
      println(table(x))
    }
  }
}

object Solution {
  val moduloP = 1e9.toInt + 7
  val upperBound = 1e5.toInt
  val ways = Array.fill(upperBound + 1)(0)
  ways(0) = 1
  val coinSizes = Array(1, 2, 5, 10, 20, 50, 100, 200)
  for {i <- 0 until coinSizes.length
       j <- coinSizes(i) to upperBound} {
     ways(j) = (ways(j) + ways(j - coinsSize(i))) % moduloP
  }

  def main(args: Array[String]) {
    val t = readLine.toInt
    for (i <- 1 to t) {
      val n = readLine.toInt
      println(ways(n))
    }
  }
}

--- 
+++ 
@@ -1,19 +1,24 @@
 object Solution {
   val moduloP = 1e9.toInt + 7
-  val upperBound = 1e5.toInt
-  val ways = Array.fill(upperBound + 1)(0)
-  ways(0) = 1
   val coinSizes = Array(1, 2, 5, 10, 20, 50, 100, 200)
-  for {i <- 0 until coinSizes.length
-       j <- coinSizes(i) to upperBound} {
-     ways(j) = (ways(j) + ways(j - coinsSize(i))) % moduloP
+
+  def countTable(coinSizes: Array[Int], n: Int): Array[Int] = {
+    val ways = Array.fill(n + 1)(0)
+    ways(0) = 1
+    for {i <- 0 until coinSizes.length
+         j <- coinSizes(i) to n} {
+      ways(j) = (ways(j) + ways(j - coinSizes(i))) % moduloP
+    }
+    ways
   }
 
   def main(args: Array[String]) {
     val t = readLine.toInt
-    for (i <- 1 to t) {
-      val n = readLine.toInt
-      println(ways(n))
+    val testCases = (1 to t).map(x => readLine.toInt)
+    val n = testCases.max
+    val table = countTable(coinSizes, n)
+    testCases foreach { x =>
+      println(table(x))
     }
   }
 }
Update the solution for problem 31.
