题目大意
有a和b两个数,可以进行两个操作:a = a / b,b = b+1。找出最小的使a=0的操作数。
思路
由题可知,a和b的最大值为10^9,考虑最极端的情况:a = 10^9,b = 2时,a / 2 的操作数为30。数据量小,我们可以考虑将一个范围内的所有操作数全部枚举出来,然后进行比较,最终找出最小操作数。
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int a, b, k;
cin >> k;
while(k--){
cin >> a >> b;
int j = 0, count = 1e9;
for(; j < 1000; j++){
int i = 0;
if(b + j < 2) continue;
int m = a;
while(m){
m /= b + j;
i++;
}
count = min(count, i + j);
}
cout << count << endl;
}
return 0;
}