#include #include using namespace std; using namespace atcoder; using ll = long long; map mp; ll solve(ll h, ll a) { if (h / a == 0) return 1; if (mp.count(h)) return mp[h]; ll res = 1; for (int i = 0; i < 2; i++) { res += solve(h / a, a); } return mp[h] = res; } int main() { ll H, A; cin >> H >> A; cout << solve(H, A) << endl; return 0; }