import Control.Monad import Debug.Trace div2 :: Integer -> Integer div2 en | odd en == True = en | otherwise = div2 $ div en 2 searchSosu :: Integer -> Integer -> Integer -> Integer searchSosu pn rootn n | pn > rootn = n | modpn == 0 = pn | otherwise = searchSosu (pn + 2) rootn n where modpn = n `mod` pn main = do n <- (read :: String -> Integer) <$> getLine let oddn = div2 n n' | n == oddn = n | oddn == 1 = n | otherwise = oddn floor_rootn = floor $ sqrt $ fromInteger (n'::Integer) rootn_1 = floor_rootn + 1 oddsosu = searchSosu 3 rootn_1 n' result | oddsosu < 4 = oddsosu | (n `mod` 4) == 0 = 4 | otherwise = oddsosu print result