【題目敘述】https://zerojudge.tw/ShowProblem?problemid=c079
#include <iostream>
using namespace std;
int main() {
int n, k;
while (cin >> n >> k){
int sum = n + n / k;
n = n / k + n % k;
while (n >= k){
n -= k;
n++;
sum++;
}
cout << sum << "\n";
}
return 0;
}
Python code (credit: Amy Chou)
while True:
try:
n, k = map(int, input().split())
ans = n + n // k
n = n // k + n % k;
while n >= k:
n -= k
n += 1
ans += 1
print(ans)
except:
break
while True:
try:
n, k = map(int, input().split())
print(n + n // k + (n // k + n % k) // k)
except:
break