from functools import lru_cache n, a = map(int, input().split()) @lru_cache(maxsize=10**8) def dfs(val): if val == 1: return 1 return 1 + dfs(val // a) + dfs(val // a) print(dfs(n))