Problem:
Score : 300 points

Problem Statement

You are given an integer N.
Find the number of the positive divisors of N!, modulo 10^9+7.

Constraints

1≤N≤10^3

Input

The input is given from Standard Input in the following format:

N

Output

Print the number of the positive divisors of N!, modulo 10^9+7.

Sample Input 1

3

Sample Output 1

4

There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.

Sample Input 2

6

Sample Output 2

30

Sample Input 3

1000

Sample Output 3

972926972

Solution in Scala (2.11.7) (judge verdict: Accepted)

import scala.io.StdIn.readLine
import scala.annotation.tailrec

object Main extends App {
  val n = readLine.toInt

  def candidates(n: Int) = if (n < 4) Nil else 2 +: (3 to math.sqrt(n).toInt by 2)
  def isPrime(n: Int) = candidates(n).forall(n % _ != 0)
  def primeFactorize(n: Int): List[Int] =
    if (isPrime(n)) List(n)
    else {
      @tailrec def recur(n: Int, res: List[Int]): List[Int] =
        candidates(n).reverse.find(k => n % k == 0 && isPrime(k)) match {
          case Some(p) => recur(n / p, p :: res)
          case None => n :: res
        }
      recur(n, Nil)
    }

  def buildPQs(pqs: Map[Int, Int], xs: Seq[Int]): Map[Int, Int] = {
    def helper(pqs: Map[Int, Int], ps: Seq[Int]): Map[Int, Int] =
      if (ps.isEmpty) pqs
      else {
        val p = ps.head
        val q = if (pqs isDefinedAt p) pqs(p) else 0
        helper(pqs + (p -> (q + 1)), ps.tail)
      }
    if (xs.isEmpty) pqs
    else buildPQs(helper(pqs, primeFactorize(xs.head)), xs.tail)
  }

  val pqs = buildPQs(Map[Int, Int](), 2 to n)
  var res = 1L
  pqs foreach {
    case (p, q) => res = res * (q + 1) % 1000000007
    case _ =>
  }
  println(res)
}