99-haskell-problems/Problems 31-41/problem_35.hs

10 lines
265 B
Haskell

import Data.List (find)
isqrt :: (Integral n) => n -> n
isqrt = floor . sqrt . fromIntegral
primeFactors :: (Integral n) => n -> [n]
primeFactors n =
case find ((== 0) . (n `mod`)) [2 .. isqrt n] of
Nothing -> [n]
Just m -> m : primeFactors (n `div` m)