luogu#P5083. 函数

函数

Problem Description

Xiaoben has a binary function f(a,b)f(a,b).

If a<2a<2 or b<2b<2, it returns a+ba+b.

Otherwise, it returns the maximum of the following four expressions (all divisions are integer divisions):

a+ba+b g(a/2)+g(a/3)+g(a/8)+g(a/9)+bg(a/2)+g(a/3)+g(a/8)+g(a/9)+b g(b/2)+g(b/3)+g(b/8)+g(b/9)+ag(b/2)+g(b/3)+g(b/8)+g(b/9)+a $$g(b/2)+g(b/3)+g(b/8)+g(b/9)+g(a/2)+g(a/3)+g(a/8)+g(a/9)$$

Here, g(n)g(n) returns max(g(n/2)+g(n/3)+g(n/8)+g(n/9),n)\max(g(n/2)+g(n/3)+g(n/8)+g(n/9),n), and it returns 00 when n=0n=0.

Of course, even an idiot can figure out that you can use memoization to compute smaller values of f(a,b)f(a,b), so Xiaoben will not test you with such an easy problem.

He wants you to find the value of f(a,b)f(a,b) when both aa and bb are less than 101610^{16}.

Input Format

The input contains multiple test cases.

Each test case consists of one line with two positive integers a,ba,b.

Output Format

For each test case, output one line containing the value of f(a,b)f(a,b).

5 6
1 1
1 223
11
2
224

Hint

For 40%40\% of the testdata, a,b<107a,b<10^7.

For 70%70\% of the testdata, the time limit is 22 seconds.

For 100%100\% of the testdata, a,b<1016a,b<10^{16}. The number of test cases does not exceed 10410^4.

Translated by ChatGPT 5