http://codeforces.com/problemset/problem/1485/A
这个题感觉比b,c题还烦。不好想到。
#include <bits/stdc++.h>
//#define int long long
#define ll long long
using namespace std;
template <class cl>
void read(cl &x)
{
x = 0;
int f = 0;
char ch;
ch = getchar();
while (!isdigit(ch))
{
f = f | (ch == '-'), ch = getchar();
}
while (isdigit(ch))
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = f ? -x : x;
return;
}
template <class cl>
void put(cl x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
put(x / 10);
putchar(x % 10 + '0');
return;
}
int a, b;
int ans = 0;
int nn=100;
int res;
int aa;
int bb;
/*inline void to()
{
read(a);
read(b);
if (a < b)
{
puts("1");
}
else
{
while (1)
{
if(a==0) break;
if ((a - a / b) * 2 > a - (a / (b + 1)))
{
a = a / b;
ans += 1;
}
else
{
b = b + 1;
a = a / b;
ans += 2;
}
}
put(ans);
puts("");
}
return ;
}*/
// 步骤1与步骤2交叠进行显然不如步骤二进行到一定程度后再一直进行步骤一。
inline void to()
{
read(a);
read(b);
aa=a;//这里容易写反,易错。
bb=b;
ans=0;
nn=100;//勿忘。
if(a==0)
{
puts("0");
return ;
}
if(a<b)
{
puts("1");
return ;
}
if(a==b)
{
puts("2");
return ;
}
if(b<2)
{
for(int i=2-b;i<=nn;i++)
{//这里的更新nn的值很好用。因为要找的步骤数要比现有的要小。这样时间复杂度就下来了。
ans=0;//勿忘值为零
a=aa;//这里a与b要被重置 ,勿忘。
b=bb;
b=b+i;
ans+=i;
while(1)
{
if(a==0)break;
a=a/b;
ans++;
}
if(ans<=nn)
{
nn=ans;res=ans;
}
}
}
else
{
for(int i=0;i<=nn;i++)
{
ans=0;//勿忘值为零
a=aa;
b=bb;
b=b+i;
ans+=i;
while(1)
{
if(a==0) break;
a=a/b;
ans++;
}
if(ans<=nn)
{
nn=ans;
res=ans;
}
}
}
put(res);
puts("");
return ;
}
signed main()
{
// cout<<(1<<30)<<endl;
int t;
read(t);
while (t--)
{
to();
}
return 0;
}