题目描述
We define a function f(x) over all non-negative integer x as follows:
f(x)=⎩⎨⎧1f(3x)+1f(x−1)+1(x=0)(x>0∧xmod3=0)(x>0∧xmod3=0)Calculate maxx=lrf(x).
You need to answer T queries independently.
输入格式
The first line contains a single integer T (1≤T≤104).
Each of the next T lines contains two integers l and r (1≤l≤r≤1018), representing a query.
输出格式
Output T lines. The i-th line contains a single integer, representing the answer to the i-th query.
题目大意
题目描述
定义在所有非负整数 x 上的函数 f(x) 如下:
f(x)=⎩⎨⎧1f(3x)+1f(x−1)+1(x=0)(x>0∧xmod3=0)(x>0∧xmod3=0)计算 maxx=lrf(x)。
共有 T 组数据。
1≤T≤104,1≤l≤r≤1018。
输入格式
第一行一个整数 T。
接下来 T 行,每行两个整数 l,r 表示一组询问。
输出格式
对于每组询问,输出一行一个整数表示答案。
提示
Source: The 2022 ICPC Asia Xi'an Regional Contest Problem E.
Author: MagicSpark.