w = int(input()) d = int(input()) for i in range(d-1): y = w//d**2 w -= y d -= 1 print(w)