#include #include using namespace std; using namespace atcoder; int main(){ long long h, a; cin >> h >> a; long long res = 0, now = 1; while(h > 0){ res += now; h /= a; now *= 2; } cout << res << endl; }