1

Given a sequence of natural numbers $a_1, a_2,..., an$ in one operation you can choose 2 adjacent elements and subtract the value of the smaller one from the bigger one and remove the smallest one. In case the values are equal, you can remove any of them. Now you have to repeat this process $n-1$ times, until there is only one value left. Now, the question is, what is the set of all possible values remaining at the end. Let me give you an example. If we have the numbers $1,4,3,6,6$, in one operation, we can the sequence $1,4,3,0$ by subtracting 6 from one element and deleting the other. After that we can get $3,3,0$ by subtracting $1$ from $4$ and removing the $1$. Then we can get $3,3$ and then $0$. So, from the initial set $1,4,3,6,6$ we got $0$. There are also other possible values we can get at the end. the number of elements is maximum 50. The best idea i got is brute force.

Nathaniel
  • 18,309
  • 2
  • 30
  • 58
John
  • 41
  • 3

1 Answers1

1

This is impossible to solve in $o(2^n)$ due to the output size. Consider $a_i = 2^{i-1}$. We'll show inductively that all odd positive integers up to $2^{n-1}$ are possible.

This is trivially true in the base case ($n = 1$). Suppose this is true for $n = k$. For $n = k+1$, we may get any number possible with $n = k$ by applying the operation to $a_k, a_{k+1}$; we may get $2^k - $ (any number possible with $n = k$) by reducing the first $k$ values first. The union of these two sets is the set of all odd positive integers up to $2^{n-1}$.

By induction, our claim holds for all positive integers $n$.

Since there are about $2^{n-2}$ odd positive integers up to $2^{n-1}$, this problem is infeasible under the constraint $n \le 50$.