Proper divisors: Difference between revisions

m
Line 2,004:
<lang haskell>import Data.List (maximumBy)
import Data.Ord (comparing)
import ControlData.MonadBool (apbool)
 
properDivisors
Line 2,012:
let root = (floor . sqrt . fromIntegral) n
lows = filter ((0 ==) . rem n) [1 .. root]
in init (lows ++ bool id tail (n == root * root) (reverse (quot n <$> lows)))
in init
(lows ++
(if root * root == n
then tail
else id)
(reverse (quot n <$> lows)))
 
main :: IO ()
Line 2,032 ⟶ 2,027:
print $
maximumBy (comparing snd) $
ap (,) <*> (length . properDivisors) <$> [1 .. 20000]</lang>
{{Out}}
<pre>Proper divisors of 1 to 10:
9,659

edits