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

11 lines
265 B
Haskell
Raw Normal View History

2024-05-26 01:13:00 -05:00
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)