-- yukicoder My Practice -- author: Leonardone @ NEETSDKASU main = readLn >>= print . g 3 . f 4 where f k x | m > 0 = x | otherwise = f k d where (d, m) = divMod x k g i x | x < k = x | otherwise = g (i + 2) (f k x) where k = i * i