tasks = int(input()) fights = int(input()) def cal(task, fight): rest_task = task - (task // fight**2) tomorrow_fight = fight - 1 if tomorrow_fight == 0: print(task) return return cal(rest_task, tomorrow_fight) cal(tasks, fights)