Official
B - Slimes Editorial by en_translator
As in the problem statement, “doing something repeatedly until the condition is met” can be implemented by a while statement.
As the upper bound of the answer is \(\log_2 10^9 < 30\), the answer can be found fast enough by a simulation. Be careful enough of overflows. (The product of \(A\) and \(K\) may not fit in a 32-bit integer.)
Sample code (C++):
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, k;
cin >> a >> b >> k;
int res = 0;
while (a < b) {
a *= k;
res++;
}
cout << res << endl;
}
posted:
last update: