#P9532. [YsOI2023] 前缀和
[YsOI2023] 前缀和
Background
A warm-up problem for Ysuperman’s template test.
Watch out for “Liqiu”, watch out for “Qiuli”.
Problem Description
Liqiu has an array of length . All numbers are positive integers, and except for the first number, every other number equals the sum of all previous numbers.
For example, the array could be an array Liqiu has, because except for the first number , every following number is the sum of the previous numbers, for instance:
- The second number .
- The third number .
- The fourth number .
- The fifth number .
- The sixth number .
Now Liqiu tells Qiuli that the number exists in this array. Qiuli wants to know what the minimum possible value of is, i.e., the minimum possible value of the last number of the whole array.
Input Format
This problem contains multiple test cases.
The first line contains an integer , representing the number of test cases.
The next lines each contain two positive integers .
Output Format
Output lines in total, each being the answer for one test case.
For a test case , output one line with one positive integer, representing the minimum possible .
3
2 2
3 2
4 2
2
2
4
3
3 1
3 2
3 4
2
2
4
3
2 6
3 6
4 6
6
6
12
3
3 3
3 6
3 12
6
6
12
Hint
Explanation for Sample 1
- For the first test case, the only possible array is , so the answer is .
- For the second test case, there are two possible arrays: and , so the answer is .
- For the third test case, there are two possible arrays: and , so the answer is .
Explanation for Sample 2
- For the first test case, the only possible array is , so the answer is .
- For the second test case, there are two possible arrays: and , so the answer is .
- For the third test case, there are two possible arrays: and , so the answer is .
Constraints
For the first of the testdata, is not divisible by , i.e., is not a factor of , i.e., is odd.
Another of the testdata satisfies that is divisible by , i.e., is a factor of .
Another of the testdata satisfies . It can be proven that under this constraint, the answer can be stored using an int variable.
For of the testdata, , , .
Translated by ChatGPT 5