Codeforces Round #701 (Div. 2) A. Add and Divide

学习记录


前言

被蓝桥杯🔪傻了的孩子终于来更新博客了


题目地址:

来一个还热乎的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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值