logo AlgoBeat OnlineJudge
登录 注册

#216410. [SYSUCPC 2025] Sum

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

is studying numeral systems. For a natural number , wants to know the smallest digit sum among the representations of in bases from to . For example, the natural number has a representation of in base , with a digit sum of , and a representation of in base , also with a digit sum of .

输入格式

There are multiple test cases.

The first line of input contains a positive integer , indicating the number of test cases.

The next lines each contain two positive integers .

输出格式

Output lines, each containing an integer, representing the smallest digit sum.

样例

样例输入 1

4
6 3
7 4
30 5
999967000273 999983

样例输出 1

2
3
2
3

数据范围与提示

For , the digit sum is minimized in base or base . For , the digit sum is minimized in base or base . For , the digit sum is minimized in base .