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 Haskell (GHC 7.10.3) (judge verdict: Accepted)

import Data.Array.IO
import Control.Monad

type Memo = IOUArray Int Int

main = do
  n <- readLn :: IO Int
  table <- newArray (1, n) 0 :: IO Memo
  writeArray table 1 2
  prime table 1 n [i | i <- [3..n], odd i == True]
  pList <- filter (/=0) <$> getElems table
  count <- newArray (1, length pList) 0 :: IO Memo
  foldM (divisor pList 1) count [2..n]
  cList <- map (+1) . filter (/=0) <$> getElems count
  if n == 1 then print 1
            else print $ foldl1 (\x y -> mod (x * y) $ 10^9+7) cList

count :: [Int] -> Int -> Int
count nums n = length $ filter ((==0) . mod n) nums

prime :: Memo -> Int -> Int -> [Int] -> IO Memo
prime table pn n []     = return table
prime table pn n x@(i:is) = do
  if i^2 <= n
    then do
      writeArray table (pn+1) i
      let is' = filter ((/=0) . flip mod i) is
      prime table (pn+1) n is'
    else do
      let len = length x
          idx = [pn+1..pn+len]
      prime' $ zip idx x
      return table
            where prime' :: [(Int, Int)] -> IO Memo
                  prime' [] = return table
                  prime' ((i, n):ss) = do
                    writeArray table i n
                    prime' ss

divisor :: [Int] -> Int -> Memo -> Int -> IO Memo
divisor [] _ memo _ = return memo
divisor _  _ memo 1 = return memo
divisor p  i memo n
  | mod n (p !! (i-1)) == 0 = do
    c <- readArray memo i
    writeArray memo i $ c + 1
    divisor p 1 memo $ div n (p !! (i-1))
  | otherwise    = divisor p (i+1) memo n