A. Add and Divide

time limit per test

1 second

memory limit per test

256 megabytes

You have two positive integers a and b.

You can perform two kinds of operations:

  • a=⌊ab⌋ (replace a with the integer part of the division between a and b)
  • b=b+1 (increase b by 1)

Find the minimum number of operations required to make a=0.

Input

The first line contains a single integer t (1≤t≤100) --- the number of test cases.

The only line of the description of each test case contains two integers a, b (1≤a,b≤109).

Output

For each test case, print a single integer: the minimum number of operations required to make a=0.

Example

Input

Copy

复制代码
6
9 2
1337 1
1 1
50000000 4
991026972 997
1234 5678

Output

Copy

复制代码
4
9
2
12
3
1

Note

In the first test case, one of the optimal solutions is:

  1. Divide a by b. After this operation a=4 and b=2.
  2. Divide a by b. After this operation a=2 and b=2.
  3. Increase b. After this operation a=2 and b=3.
  4. Divide a by b. After this operation a=0 and b=3.

解题说明:此题是一道数学题,首先B需要确保至少为2,如果B为1首先需要增加B。然后再判断b是否足够大,这里采用log_b(a) > 1 + log_{b+1}(a)来判断,最后每次让a去除以b直到为0.

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() 
{
	int T; 
	cin >> T;
	while (T--) 
	{
		int a, b, c = 0;
		cin >> a >> b;
		if (b == 1)
		{
			b++;
			c++;
		}
		while (log10(a) / log10(b) > 1 + log10(a) / log10(b + 1))
		{
			b++;
			c++;
		}
		while (a)
		{
			a /= b;
			c++;
		}
		cout << c << "\n";
	}
	return 0;
}
相关推荐
Frostnova丶2 小时前
LeetCode 67. 二进制求和
算法·leetcode
上海锟联科技2 小时前
DAS 与 FBG 振动监测对比:工程应用中该如何选择?
数据结构·算法·分布式光纤传感
星火开发设计2 小时前
模板参数:类型参数与非类型参数的区别
java·开发语言·前端·数据库·c++·算法
JialBro2 小时前
【嵌入式】直流无刷电机FOC控制算法全解析
算法·嵌入式·直流·foc·新手·控制算法·无刷电机
昌兵鼠鼠2 小时前
LeetCode Hot100 哈希
学习·算法·leetcode·哈希算法
忘梓.2 小时前
二叉搜索树·极速分拣篇」:用C++怒肝《双截棍》分拣算法,暴打节点删除Boss战!
开发语言·c++·算法
人工智能AI酱2 小时前
【AI深究】高斯混合模型(GMM)全网最详细全流程详解与案例(附Python代码演示) | 混合模型概率密度函数、多元高斯分布概率密度函数、期望最大化(EM)算法 | 实际案例与流程 | 优、缺点分析
人工智能·python·算法·机器学习·分类·回归·聚类
Aileen_0v02 小时前
【数据结构中链表常用的方法实现过程】
java·开发语言·数据结构·算法·链表·动态规划·csdn开发云
逻辑流2 小时前
《精准测量的起点:STM32中的电压电流有效值计算算法》
stm32·单片机·嵌入式硬件·算法