题目大意
给你两个数字(a)和(b),让你执行两种操作:
- (a=lfloor frac{a}{b} floor)
- (b=(b+1))
问你最少需要几次操作,让(a)变成(0)
题目分析
当(a=10^9,b=1)的极限情况下,最少操作次数不超过20次,之后再去暴力枚举在20次操作内,经过上述两种操作让(a=0)最少需要几次操作。同时,需要注意,当(ble1)的时候是没有什么判断价值的,因为这个时候再去执行(lfloor frac{a}{b} floor)的次数肯定是最多的。
AC代码
#include <iostream>
#include <algorithm>
using namespace std;
int t, a, b;
inline int f(int A, int B)
{
int res = 0;
while (a) { a /= b; res++; }
return res;
}
int main()
{
scanf("%d", &t);
while (t --)
{
scanf("%d%d", &a, &b);
int res = 0x3f3f3f3f;
for (int i = 0; i < 20; i++)
{
if (b + i <= 1) continue;
res = min(res, f(a, b + i) + i);
}
cout << res << '
';
}
return 0;
}