import heapq H, A = map(int, input().split()) count = {} count[H] = 1 heap = [] heapq.heappush(heap, -H) # Using max heap by negating values ans = 0 while heap: current_h = -heapq.heappop(heap) if current_h not in count or count[current_h] == 0: continue c = count[current_h] ans += c h_new = current_h // A if h_new > 0: if h_new in count: count[h_new] += 2 * c else: count[h_new] = 2 * c heapq.heappush(heap, -h_new) count[current_h] = 0 # Mark as processed print(ans)