We're a place where coders share, stay up-to-date and grow their careers.
But here's a haskell solution just for fun:
import Data.List prime_factors :: Int -> [Int] prime_factors 1 = [] prime_factors n = next_factor : (prime_factors $ div n next_factor) where next_factor = head [i | i <- [2..n], 0 == mod n i] decomp :: Int -> [Int] decomp = sort . decomp' where decomp' 1 = [] decomp' n = prime_factors n ++ decomp' (n - 1)
But here's a haskell solution just for fun: