学习记录
前言
被蓝桥杯🔪傻了的孩子终于来更新博客了
题目地址:
来一个还热乎的cf:
Codeforces Round #701 (Div. 2) A. Add and Divide
https://codeforces.com/contest/1485/problem/A
题意解析
题意: 给出a和b两个正整数,每一步只能a=a/b或b=b+1;问最少需要多少步才能使a=0或(a < b)
突破点:
因此该题的突破点就在于寻找界定标准。
AC代码
代码如下(示例):
虽然好像没给数据范围,但是样例数值就比较大,所以采取保险的办法。
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
#define mm (1e9)
ll dfs(ll a,ll b)
{
ll p=0;
while(a)
{
a=a/b;
p++;
}
return p;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll a,b;
scanf("%lld%lld",&a,&b);
ll cnt=0;
if(b==1)
{
cnt++;
b=2;
}
ll min=mm;
ll sum;
while(1)
{
ll p=dfs(a,b);
ll sum=cnt+p;
if(sum<min)
{
min=sum;
}
cnt++;
b++;
if(cnt>=min)
{
printf("%lld\n",min);
break;
}
}
}
return 0;
}