Ad
Code
Diff
  • module Divisors where
    
    divisors :: Integer -> [Integer]
    divisors n = filter ((0 ==) . mod n) [1..n]
    • module Divisors where
    • divisors :: Integer -> [Integer]
    • divisors n = 1:n:(divisorsAux 2)
    • where
    • divisorsAux k
    • | (fromIntegral k) > sqrt (fromIntegral n) = []
    • | otherwise = if n `mod` k == 0
    • then if n`div`k ==k
    • then k:(divisorsAux (k+1))
    • else k:(n`div`k):(divisorsAux (k+1))
    • else divisorsAux (k+1)
    • divisors n = filter ((0 ==) . mod n) [1..n]