Factorização em números primos
factores n = f n ft
where
f 1 _ = []
f _ [] = []
f n l@(x:xs) | n `mod` x == 0 = x : f (n `div` x) l
| otherwise = f n xs
ft = reverse $ takeWhile (<= n) allprimes
where
allprimes = 2 : (filter isPrime [3,5..])
isPrime n = all (/= 0) . map (n `mod`) $ [2 .. squareRoot n]
where
squareRoot = truncate . sqrt . fromIntegral