Problem:
Prime Factorization

Factorize a given integer n.

Input

n

An integer n is given in a line.

Output

Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor.

Constraints

2 ≤ n ≤ 109

Sample Input 1

12

Sample Output 1

12: 2 2 3

Sample Input 2

126

Sample Output 2

126: 2 3 3 7

Solution in Haskell (judge verdict: Time Limit Exceeded)

import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  putStrLn $ solve n


solve :: Int -> String
solve n = show n ++ ": "
          ++ unwords (map show $ factrization n primes)
  where
    primes = 2 : 3 : 5 : filter f [7, 9..]
      where
        f n = all ((/= 0) . (mod n)) $
              takeWhile ((<= n) . (^ 2)) primes
    factrization :: Int -> [Int] -> [Int]
    factrization n pss@(p:ps)
      | n == 1 = []
      | n `mod` p == 0 = p : factrization (n `div` p)  pss
      | otherwise = factrization n ps