#P10797. 「CZOI-R1」进制

「CZOI-R1」进制

Problem Description

You have a number xx, and you need to perform nn operations on it.

In each operation, you may choose one valid digit of xx in base yy and increase its value by 11.
The first non-zero digit and all digits after it are considered valid digits.

Note:

  • For each operation, you may choose any y[2,+)y\in[2,+\infty).
  • You must ensure that the increment does not cause a carry in the base-yy representation of xx.

Now you need to find the maximum possible value of this number after nn operations.

Output the answer in decimal, modulo 109+710^9+7. You need to output the result of (the maximum value) modulo 109+710^9+7, not the maximum value after taking modulo 109+710^9+7.

Input Format

This problem has multiple test cases.

The first line contains an integer TT, the number of test cases.

The next TT lines each contain two integers x,nx,n, representing the initial number and the number of operations.

Output Format

For each test case, output one integer per line, representing the maximum value of xx after performing nn operations.

1
2 1
3

Hint

[Sample Explanation]

Clearly, 22 is 1010 in binary, and it is 22 in base 33 or higher.

In binary, adding 11 to the first digit would cause a carry, so you can only add 11 to the second digit. The result is 1111, which is 33 in decimal.

In base 33 or higher, you can only add 11 to the last digit. In base 33 it would cause a carry, so discard it. In base 44 or higher, the result is always 33, and the converted decimal result is also 33.

[Constraints]

This problem uses bundled testdata.

  • Subtask #1 (20 pts20\text{ pts}): x2x\le 2.
  • Subtask #2 (20 pts20\text{ pts}): n=1n=1.
  • Subtask #3 (60 pts60\text{ pts}): no special constraints.

For 100%100\% of the testdata, 1x,n1091\le x,n\le10^9, and 1T1061\le T\le10^6.

Translated by ChatGPT 5