from functools import lru_cache import sys sys.setrecursionlimit(10**5) 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))