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 qualified Data.Map as MP
import Data.Maybe
import Data.List

primeFactor :: MP.Map Int Int -> Int -> MP.Map Int Int
primeFactor m n = loop n 2 m
    where
        loop :: Int -> Int -> MP.Map Int Int ->  MP.Map Int Int
        loop n i m
            | n `rem` i == 0 = inner n i m
            | i * i > n = if n /= 1 
                then search n m
                else m 
            | otherwise = loop n (i+1) m
        
        inner ::  Int -> Int -> MP.Map Int Int -> MP.Map Int Int
        inner n i m
            | n `rem` i == 0 = let m' = search i m in inner (n `quot` i) i m'
            | otherwise = loop n (i+1) m
        
        search :: Int -> MP.Map Int Int -> MP.Map Int Int 
        search k m = case MP.lookup k m of
            Just _ -> MP.adjust (+1) k m
            Nothing -> MP.insert k 1 m

solve :: Int -> Int
solve n = loop m
    where
        m = foldl' primeFactor MP.empty [2..n] 
        mulMod a b = (a * b) `rem` (10^9+7)
        loop :: MP.Map Int Int -> Int
        loop m 
            | MP.null m = 1
            | otherwise =
                let 
                    ((_, v), m') = MP.deleteFindMin m
                in
                    mulMod (v+1) $ loop m'

main = do
    n <- readLn :: IO Int
    print $ if n == 1 then 1 else solve n