#P9362. [ICPC 2022 Xi'an R] Find Maximum
[ICPC 2022 Xi'an R] Find Maximum
题目描述
We define a function over all non-negative integer as follows:
$$f(x) = \begin{cases} 1 & (x = 0) \\ f(\frac{x}{3}) + 1 & (x > 0\land x\bmod3 = 0) \\ f(x - 1) + 1 & (x > 0\land x\bmod 3\neq 0) \end{cases} $$Calculate .
You need to answer queries independently.
输入格式
The first line contains a single integer ().
Each of the next lines contains two integers and (), representing a query.
输出格式
Output lines. The -th line contains a single integer, representing the answer to the -th query.
10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
3
3
4
5
3
4
5
4
5
5
提示
Source: The 2022 ICPC Asia Xi'an Regional Contest Problem E.
Author: MagicSpark.