Let be a positive integer. There are boxes each of which contains some balls. One can perform the following moves.
Choose positive integers and with , and add exactly one ball to each of the boxes .
For positive integers , let be the minimum number of moves required to make the number of balls in each of boxes divisible by , starting from balls in for each . Find the maximum value of .
(If for , then )
Solution
The answer is .
For , let where . Note that . The move in the problem is equivalent to the following.
Choose non-negative integers and with , and replace and by and , respectively.
We call this move the -move. Our goal is to make each a multiple of . Now we prove that for every sequence of integers with , we can make each of 's a multiple of by performing at most moves.
We use induction on .
One can easily check that it is possible when .
Suppose . If for some , then we can ignore , and so we need at most moves to make all 's multiples of . Hence, we may assume that for each . We consider the following four cases.
Case 1. There exist such that and .
Then, we perform the -move then and become multiples of . So, in this case, we need at most moves.
Case 2. There exist such that .
Then, we perform the -move and the -move. Then, and become multiples of . So, we need at most moves.
Case 3. There exist such that .
Then, we perform the -move and the -move. Then, and become multiples of . So, we need at most moves.
Case 4. Neither case 1, case 2 nor case 3 occurs.
Since , the only possible case is that and . In this case, we perform the (0, 1)-move, the (0, 3)-move and the (2, 3)-move. Then, each becomes a multiple of .
Therefore, by the induction, we can make each a multiple of by performing at most moves.
Finally, for the following cases, we need at least moves, which implies that the answer is .