Largest proper divisor of n: Difference between revisions
Content added Content deleted
Line 283: | Line 283: | ||
(Otherwise, the largest proper divisor will be 1 itself). |
(Otherwise, the largest proper divisor will be 1 itself). |
||
<lang haskell>import Data.List |
<lang haskell>import Data.List (find) |
||
import Data.List.Split (chunksOf) |
|||
import Text.Printf (printf) |
import Text.Printf (printf) |
||
maxProperDivisors :: Int -> Int |
maxProperDivisors :: Int -> Int |
||
maxProperDivisors n |
maxProperDivisors n = |
||
case find ((0 ==) . rem n) [2 .. root] of |
|||
| null xs = 1 |
|||
Nothing -> 1 |
|||
| otherwise = quot n (head xs) |
|||
Just x -> quot n x |
|||
where |
where |
||
root = (floor . sqrt) (fromIntegral n :: Double) |
root = (floor . sqrt) (fromIntegral n :: Double) |
||
xs = take 1 [x | x <- [2 .. root], 0 == rem n x] |
|||
main :: IO () |
main :: IO () |