#include using namespace std; #define int unsigned long long signed main(){ int h,a; cin >> h >> a; vector b; while(true){ if(h == 0) break; b.push_back(h); h /= a; } int c = (int)b.size(); vector d(c); int k = 1; for(int i = 0;i < c;i++){ d[i] = k; k *= 2; } int ans = 0; for(int i = 0;i < c;i++){ ans += d[i]; } cout << ans << endl; }