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;
}
相关推荐
凤凰院凶涛QAQ1 分钟前
《Java版数据结构 & 集合类剖析》集合框架的封装设计与顺序表:“从 Iterable 到 ArrayList:集合框架的‘职业树“
java·开发语言·数据结构
吴可可12313 分钟前
Win7上开发CAD2004自定义实体全解析
c++·算法
YXXY31315 分钟前
二叉树中的深搜算法介绍
算法
zz345729811317 分钟前
C语言中字符串常量存储位置
c语言·开发语言·算法·青少年编程
noipp18 分钟前
推荐题目:洛谷 P16510 [GKS 2015 #C] gRanks
java·c语言·开发语言·c++·python·算法
菜菜的顾清寒27 分钟前
力扣HOT100(50)动态规划-零钱兑换
算法·leetcode·动态规划
周末也要写八哥30 分钟前
三分钟读懂:如何解决做题数量不足的问题?
算法
8Qi832 分钟前
LeetCode 148. 排序链表 —— 解法二:自底向上归并(迭代,O(1) 空间)
数据结构·算法·leetcode·链表·归并·迭代
嘿黑嘿呦34 分钟前
数据结构-图论-最小生成树
数据结构·算法·图论
Justice Young42 分钟前
算法分析与设计实验:贪心法求解0/1背包问题的局限性
算法