You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
276 B

#include<bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int ans = 0;
int num = 0;
while (n > 0) {
ans += n;
int x = n + num;
num = x % k;
n = x / k;
}
cout << ans << endl;
return 0;
}