solve :: Int -> Int -> Int solve w 1 = w solve w d = solve (w-t) (d-1) where t = w `div` (d^2) main :: IO () main = do w <- readLn :: IO Int d <- readLn :: IO Int print $ solve w d