Let \(n\) be a positive integer. We start with \(n\) piles of pebbles, each initially containing a single pebble. One can perform moves of the following form: choose two piles, take an equal number of pebbles from each pile and form a new pile out of these pebbles. Find (in terms of \(n\)) the smallest number of nonempty piles that one can obtain by performing a finite sequence of moves of this form.
Answer: \(1\) if \(n\) is a power of two, and \(2\) otherwise.
The solution we describe is simple, but not the most effective one.
We can combine two piles of \(2^{k-1}\) pebbles to make one pile of \(2^{k}\) pebbles. In particular, given \(2^{k}\) piles of one pebble, we may combine them as follows:
\[\begin{array}{lll} 2^{k} \text { piles of } 1 \text { pebble } & \rightarrow 2^{k-1} \text { piles of } 2 \text { pebbles } \\ 2^{k-1} \text { piles of } 2 \text { pebbles } & \rightarrow 2^{k-2} \text { piles of } 4 \text { pebbles } \\ 2^{k-2} \text { piles of } 4 \text { pebbles } & \rightarrow 2^{k-3} \text { piles of } 8 \text { pebbles } \\ & \vdots & \\ 2 \text { piles of } 2^{k-1} \text { pebbles } & \rightarrow 1 \text { pile of } 2^{k} \text { pebbles } \end{array}\]
This proves the desired result in the case when \(n\) is a power of \(2\). If \(n\) is not a power of \(2\), choose \(N\) such that \(2^{N}<n<2^{N+1}\). Let \(m=n-2^{N}\). Then \(0<m<2^{N}\). Make a pile of \(2^{N}\) pebbles and call it the large pile. (Alternatively, one can be more efficient and make a pile of \(2^{M}\) pebbles where \(m \leqslant 2^{M}\).) Since \(n\) is not a power of two, there is at least one other pile with pebbles. All other piles have a single pebble (initial condition). Choose one single pebble pile and remove the pebble and one pebble from the large pile and form a pile of \(2\) pebbles. If \(m<2^{N}-1\), remove another pebble from the large pile and one pebble from the \(2\)-pile and form a new pile of \(2\) pebbles. Repeat until the large pile contains exactly \(m\) pebbles. At this point we have one pile of \(m\) pebbles, one pile of \(2\) pebbles, and the rest are single pebble piles. There must be \(n-m-2=2^{N}-2\) single piles. Combine two and two into piles of two pebbles. Then there are \(2^{N-1}\) piles of two pebbles, which we can make into one pile of \(2^{N}\) pebbles. We are left with exactly two piles of pebbles. Lastly we will prove that it is not possible to form a single pile with all pebbles when \(n\) is not a power of two. A move consists of choosing two piles of say \(a\) and \(b\) pebbles, then removing \(c \leqslant \min (a, b)\) pebbles from both piles, and forming a new pile with \(2 c\) pebbles. If we include piles of zero pebbles, then this move changes the number of pebbles in three piles as follows (and leaves all other piles unchanged):\[\begin{array}{lll} a & \rightarrow a-c \\ b & \rightarrow b-c \\ 0 & \rightarrow 2 c \end{array}\]
Assume that after the move the number of pebbles in each pile is divisible by an odd integer \(m\). In particular, \(m|2 c, m| a-c\) and \(m \mid b-c\). Since \(m\) is odd, it follows that \(m \mid c\), and then that \(m \mid a\) and \(m \mid b\). Hence also before the move the number of pebbles in each pile is divisible by the integer \(m\). If \(n\) is not a power of 2 , then \(n\) is divisible by an odd integer \(m>1\). In order to make a single pile of \(n\) pebbles, we would have to start with a distribution in which the number of pebbles in each pile is divisible by the integer \(m\). This is impossible when we start with all piles containing a single pebble. Remarks on starting configurations From any starting configuration that is not a single pile, if there are at least two piles with at least two pebbles, we can remove one pebble from two such piles, and form a new pile with \(2\) pebbles. We can repeat this until we have one pile of \(2\) pebbles and the rest are single pebble piles, and then proceed as in the solution. Hence, if \(n\) is a power of two, we can make a single pile from any starting configuration. If \(n\) is of the form \(n=2^{k} m\) where \(m>1\) is odd, then we can make a single pile from any starting configuration in which the number of pebbles in each pile is divisible by the integer \(m\), otherwise two piles is the best we can do. Half of this is proven already. For the other half, assume we start with a configuration in which the number of pebbles in each pile is divisible by the integer \(m\). Replace each pile of \(t m\) pebbles with a pile of \(t\) boulders. We now have a total of \(2^{k}\) boulders, hence we can make them into one pile of \(2^{k}\) boulders. Replacing the boulders with pebbles again, we are done.We show an alternative strategy if \(n\) is not a power of \(2\). Write \(n\) in binary form: \(n=2^{i_{1}}+2^{i_{2}}+\cdots+2^{i_{k}}\), where \(i_{1}>i_{2}>\cdots>i_{k}\). Now we make piles of sizes \(2^{i_{1}}, 2^{i_{2}}, \ldots, 2^{i_{k}}\). We call the pile with \(2^{i_{1}}\) the large pile, all the others are the small piles.
The strategy is the following: take the two smallest small pile. If they have the same size of \(2^{a}\), we make a pile of size \(2^{a+1}\). If they have different sizes, we double the smaller pile using the large pile (we allow the large pile to have a negative number of pebbles: later we prove that it is not possible). We call all the new piles small. When we have only one small pile, we terminate the process: we have at most \(2\) piles.
After each move we have one less number of piles, and all the piles have cardinality power of 2. The number of pebbles is decreasing, and at the end of the process, it has a size of \(n-2^{i_{2}+1} \geqslant n-2^{i_{1}}>0\), thus we can manage to have two piles.
Throughout the solution, we will consider the moves in reverse order. Namely, imagine we have some piles of pebbles, and we are allowed to perform moves as follows: take a pile with an even number of pebbles, split it into two equal halves and add the pebbles from each half to a different pile, possibly forming new piles (we may assume for convenience that there are infinitely many empty piles at any given moment). Given a configuration of piles \(\mathcal{C}\), we will use \(|\mathcal{C}|\) to denote the number of non-empty piles in \(\mathcal{C}\). Given two configurations \(\mathcal{C}_{1}, \mathcal{C}_{2}\), we will say that \(\mathcal{C}_{2}\) is reachable from \(\mathcal{C}_{1}\) if \(\mathcal{C}_{2}\) can be obtained by performing a finite sequence of moves starting from \(\mathcal{C}_{1}\). Call a configuration of piles \(\mathcal{C}\)
The problem asks to find the smallest number of non-empty piles in a solvable configuration consisting of \(n\) pebbles. We begin the process of answering this question by making the following observation:
Lemma 1: Let \(\mathcal{C}\) be a configuration of piles. Let \(\mathcal{C}^{\prime}\) be a configuration obtained by applying a single move to \(\mathcal{C}\). Then
i. if \(\mathcal{C}^{\prime}\) has the odd divisor property, then so does \(\mathcal{C}\);
ii. the converse to (i) holds if \(\left|\mathcal{C}^{\prime}\right| \geqslant|\mathcal{C}|\).
Proof: Suppose that the move consists of splitting a pile of size \(2a\) and adding \(a\) pebbles to each of two piles of sizes \(b\) and \(c\). Here, \(a\) is a positive integer and \(b, c\) are non-negative integers. Thus, \(\mathcal{C}^{\prime}\) can be obtained from \(\mathcal{C}\) by replacing the piles of sizes \(2a, b, c\) by two piles of sizes \(a+b\) and \(a+c\). Note that the extra assumption \(\left|\mathcal{C}^{\prime}\right| \geqslant|\mathcal{C}|\) of part (ii) holds if and only if at least one of \(b, c\) is zero.
i. Suppose \(\mathcal{C}\) doesn't have the odd divisor property, i.e. there exists an odd integer \(d>1\) such that the size of each pile in \(\mathcal{C}\) is divisible by \(d\). In particular, \(2 a, b, c\) are multiples of \(d\), so since \(d\) is odd, it follows that \(a, b, c\) are all divisible by \(d\). Thus, \(a+b\) and \(a+c\) are also divisible by \(d\), so \(d\) divides the size of each pile in \(\mathcal{C}^{\prime}\). In conclusion, \(\mathcal{C}^{\prime}\) doesn't have the odd divisor property.
ii. If \(\mathcal{C}^{\prime}\) doesn't have the odd divisor property and at least one of \(b, c\) is zero, then there exists an odd integer \(d>1\) such that the size of each pile in \(\mathcal{C}^{\prime}\) is divisible by \(d\). In particular, \(d\) divides \(a+b\) and \(a+c\), so since at least one of these numbers is equal to \(a\), it follows that \(d\) divides \(a\). But then \(d\) must divide all three of \(a, b\) and \(c\), and hence it certainly divides \(2 a, b\) and \(c\). Thus, \(\mathcal{C}\) doesn't have the odd divisor property, as desired.
Lemma 2: If \(\mathcal{C}_{2}\) is reachable from \(\mathcal{C}_{1}\) and \(\mathcal{C}_{2}\) has the odd divisor property, then so does \(\mathcal{C}_{1}\). In particular, any solvable configuration has the odd divisor property.
Proof: The first statement follows by inductively applying part (i) of Lemma 1. The second statement follows from the first because every simple configuration has the odd divisor property.
The main claim is the following:
Lemma 3: Let \(\mathcal{C}\) be a good configuration. Then there exists a configuration \(\mathcal{C}^{\prime}\) with the following properties:
Proof: Call a configuration terminal if it is a counterexample to the claim. The following claim is at the heart of the proof:
Claim: Let \(a_{1}, \ldots, a_{k}\) be the numbers of pebbles on the non-empty piles of a terminal configuration \(\mathcal{C}\). Then there exists a unique \(i \in[k]\) such that \(a_{i}\) is even. Moreover, for all \(t \geqslant 1\) we have \(a_{j} \equiv \frac{a_{i}}{2}\left(\bmod 2^{t}\right)\) for all \(j \neq i\).
Proof of Claim: Since the configuration is good, there must exist \(i \in[k]\) such that \(a_{i}\) is even. Moreover, by assumption, if we split the pile with \(a_{i}\) pebbles into two equal halves, the resulting configuration will not be good. By part (ii) of Lemma 2,the only way this can happen is that \(\frac{a_{i}}{2}\) and \(a_{j}\) for all \(j \neq i\) are odd. To prove the second assertion, we proceed by induction on \(t\), ith the case \(t=1\) already being established. If \(t \geqslant 2\), then split the pile with \(a_{i}\) pebbles into two equal halves and move one half to the pile with \(a_{j}\) pebbles. Since \(\frac{a_{i}}{2}\) and \(a_{j}\) are both odd, \(a_{j}+\frac{a_{i}}{2}\) is even, so by part (ii) of Lemma 2, the resulting configuration \(\mathcal{C}^{\prime}\) is good. Thus, \(\mathcal{C}^{\prime}\) is terminal, so by the induction hypothesis, we have \(\frac{a_{i}}{2} \equiv \frac{1}{2}\left(a_{j}+\frac{a_{i}}{2}\right)\left(\bmod 2^{t-1}\right)\), whence \(a_{j} \equiv \frac{a_{i}}{2} \pmod {2^{t}}\)), as desired.
Suppose for contradiction that there exists a configuration as in the Claim. It follows that there exists \(i \in[k]\) and an odd integer \(x\) such that \(a_{i}=2 x\) and \(a_{j}=x\) for all \(j \neq i\). Thus, \(x\) is an odd common divisor of \(a_{1}, \ldots, a_{k}\), so by the odd divisor property, we must have \(x=1\). But then we can obtain a simple configuration by splitting the only pile with two pebbles into two piles each consisting of a single pebble, which is a contradiction.
With the aid of Lemmas 2 and 3, it is not hard to characterise all solvable configurations: Lemma 4. A configuration of piles \(\mathcal{C}\) is solvable if and only if it is simple or good.
Proof: (\(\Longrightarrow\)) Suppose \(\mathcal{C}\) is not simple. Then since we have to be able to perform at least one move, there must be at least one non-empty pile in \(\mathcal{C}\) with an even number of pebbles. Moreover, by Lemma 2, \(\mathcal{C}\) has the odd divisor property, so it must be good.
\((\Longleftarrow)\) This follows by repeatedly applying Lemma 3 until we reach a simple configuration. Note that the process must stop eventually since the number of non-empty piles is bounded from above.
Finally, the answer to the problem is implied by the following corollary of Lemma 4: Lemma 5. Let \(n\) be a positive integer. Then
(i) a configuration consisting of a single pile of \(n\) pebbles is solvable if and only if \(n\) is a power of two;
(ii) if \(n \geqslant 2\), then the configuration consisting of piles of sizes 2 and \(n-2\) is good.
Proof: (i) By Lemma 4, this configuration is solvable if and only if either \(n=1\) or \(n\) is even and has no non-trivial odd divisor, so the conclusion follows.
(ii) Since 2 is even and has no non-trivial odd divisor, this configuration is certainly good, so the conclusion follows by Lemma 4.
Instead of choosing pebbles from two piles, one could allow choosing an equal number of pebbles from each of \(k\) piles, where \(k \geqslant 2\) is a fixed (prime) integer. However, this seems to yield a much harder problem - if \(k=3\), numerical evidence suggests the same answer as in the case \(k=2\) (with powers of two replaced by powers of three), but the case \(k=5\) is already unclear.