divisors n = f n 1 where f n i | i * i > n = [] | n `rem` i == 0 = i : (f n (i + 1)) | otherwise = f n (i + 1) divisors2 n ds = map (\x -> [x, n `quot` x]) . takeWhile (\x -> x ^ 2 <= n) $ ds divisors3 n = concat . map (\x -> map (x : ) (divisors2 (n `quot` x) ds)) . takeWhile (\x -> x ^ 3 <= n) $ ds where ds = divisors n evaluate (p : q : r : []) = (p - 1) + (q - 1) + (r - 1) solveMin = minimum . map evaluate . divisors3 solveMax = (+ (-1)) main = do n <- readLn :: IO Integer putStrLn $ (show . solveMin) n ++ " " ++ (show . solveMax) n