#P9532. Minimum Final Value in Liqiu's Array

    ID: 22679 Type: Default 1000ms 256MiB

Minimum Final Value in Liqiu's Array

Minimum Final Value in Liqiu's Array

In this problem, Liqiu has an array \(a\) of length \(n\) consisting of positive integers. The array satisfies the following property: for every \(i\) from 2 to \(n\),
\[ a_i = \sum_{j=1}^{i-1} a_j, \]that is, every element except the first one is equal to the sum of all previous elements.

For example, the array \([1, 1, 2, 4, 8, 16]\) is valid because:

  • \(a_2 = 1 = a_1\),
  • \(a_3 = 1+1 = 2\),
  • \(a_4 = 1+1+2 = 4\),
  • \(a_5 = 1+1+2+4 = 8\),
  • \(a_6 = 1+1+2+4+8 = 16\).

Now, Liqiu tells Qiuli that a given positive integer \(x\) appears somewhere in the array. Qiuli wants to determine the minimum possible value of the last element \(a_n\) among all arrays satisfying the above conditions and containing \(x\) as one of the elements.

Observation: If we set the first element \(a_1 = k\) (for some positive integer \(k\)), then the array is uniquely determined as follows:

  • \(a_1 = k\),
  • \(a_2 = k\),
  • \(a_3 = 2k\),
  • \(a_4 = 4k\),
  • ... ,
  • \(a_i = 2^{i-2} \times k \) for \(i\ge 2\).

Thus, if \(x\) is chosen to be the \(i\)-th element, then we must have:

[ a_i = 2^{i-2} \times k = x \quad (\text{for } i \ge 2), ]

which implies \(k = \frac{x}{2^{i-2}}\) (and it must be a positive integer). The final element is

[ a_n = 2^{n-2} \times k = 2^{n-2} \times \frac{x}{2^{i-2}} = 2^{n-i} \times x. ]

We want to minimize \(a_n\) among all valid choices of \(i\) (where \(1 \le i \le n\) with the convention that when \(i=1\), we take \(x=a_1\) and then \(a_n = 2^{n-2} \times x\) if \(n \ge 2\), or \(a_n=x\) when \(n=1\)). Notice that potentially choosing a larger \(i\) (i.e. more division by a power of 2) can lead to a smaller value of \(a_n\) provided the divisibility condition is met.

Your task is to compute the minimum possible value of \(a_n\) given \(n\) and \(x\).

inputFormat

The input consists of a single line containing two positive integers \(n\) and \(x\) where \(n\) is the length of the array and \(x\) is the value that appears in the array.

outputFormat

Output a single integer, which is the minimum possible value of \(a_n\) under the given conditions.

sample

6 1
16