Largest proper divisor of n: Difference between revisions

Content added Content deleted
Line 288: Line 288:
maxProperDivisors :: Int -> Int
maxProperDivisors :: Int -> Int
maxProperDivisors n
maxProperDivisors n
| 1 < length ab = quot n (last ab)
| null xs = 1
| otherwise = 1
| otherwise = quot n (head xs)
where
where
root = (floor . sqrt) (fromIntegral n :: Double)
root = (floor . sqrt) (fromIntegral n :: Double)
ab = take 2 [x | x <- [1 .. root], 0 == rem n x]
xs = take 1 [x | x <- [2 .. root], 0 == rem n x]


main :: IO ()
main :: IO ()