Given two positive integers![]()
and
![]()
, calculate the sum of the digits of
in base
, denoted as
. Formally, let the sequence
satisfy the following conditions:
It can be proven that such a sequence
![]()
![]()
![]()
is unique. You need to calculate
.
Given two positive integers![]()
and
![]()
, you need to find a base
(
) such that the sum of the digits of
in base
is minimized. You only need to output the minimum value. Formally, you need to calculate
.
This problem has multiple test cases. The first line contains a positive integer![]()
, denoting the number of test cases.
The only line of each test case contains two integersand
(
,
).
For each test case, output an integer in one line, denoting the answer.
In the first test case of the sample test, you may choose, and that
. It can be proven this is the minimum possible value of
over all
.