Find the smallest possible last value of an increasing array after fixing the first element and the length.
You are given two integers, and .
Construct a strictly increasing array of length such that:
- the first element is ,
- the array uses positive integers,
- and among all valid arrays, the last element is as small as possible.
Return that minimum possible last element.
A useful way to think about the problem is that you are not asked to output the whole array, only the smallest achievable ending value for a valid increasing sequence starting at .
This problem is about how the binary representation of numbers can be used to place the additional elements while keeping the final value minimal.
Input Format
- A single test case is given.
- Two integers are provided: and .
Output Format
- Return the minimum possible last element of a valid strictly increasing array of length whose first element is .
Constraints
- The answer may require 64-bit integer arithmetic.
Example 1
Input
n = 3, x = 4
Output
6
Explanation
One optimal array is [4, 5, 6]. The last value is 6, and no valid array of length 3 starting with 4 can end smaller.
Example 2
Input
n = 4, x = 2
Output
7
Explanation
One optimal array is [2, 3, 6, 7]. The ending value 7 is minimal among all valid choices.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.