给定数字 a、b,可以进行如下两种操作:(1) a = ⌊ a b ⌋ a = \lfloor \frac{a}{b} \rfloor a=⌊ba⌋;(2) b = b + 1 b = b + 1 b=b+1,问最少进行多少次操作才能将 a 变为 0,有 t 组数据。 1 ≤ a , b ≤ 1 0 9 1 \le a,b \le 10^9 1≤a,b≤109, 1 ≤ t ≤ 100 1\le t \le 100 1≤t≤100。
#include
#include
#include
#include
#include
#include
//#include
//#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(k); 输出k位精度
//cout << setw(k); 设置k位宽度
const int N = 2e5 + 6, M = 1e9 + 7, INF = 0x3f3f3f3f;
int main() {
//freopen("/Users/xumingfei/Desktop/ACM/test.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
int ans = 2e9;
for (int i = 0; i <= 30; i++) {
if (b + i == 1) continue;
int x = a, now = 0;
while (x > 0) {
now++;
x /= b + i;
}
ans = min(ans, now + i);
}
cout << ans << '\n';
}
return 0;
}