5. Mickey writes down on a board $n$ consecutive whole numbers the smallest of which is 2023 . He then replaces the largest two numbers on the board with their difference, reducing the number of numbers on the board by one. He does this repeatedly until there is only a single number on the board. For which values of $n$ is this last remaining number 0 ?
Solution
Note that subtracting two numbers and replacing by the difference does not change the parity of the sum of the numbers: If both numbers are odd or both numbers are even then both their sum and their difference are even; if one is odd and one is even then both their sum and their difference are odd.

This means if the total sum originally is odd, the last number must be odd and therefore cannot be 0 . This happens whenever $n$ is 1 more than a multiple of 4 or 2 more than a multiple of 4 , so these values of $n$ cannot leave 0 as the remaining number.
The largest two numbers on the board are consecutive, so are replaced by 1 . Since 1 is never going to be larger than any number already on the board, the remaining largest two numbers will again be consecutive and be replaced by 1 until there are not two of the original list to remove.

If $n$ is a multiple of 4 , all the original numbers will have been replaced by an even number of 1 's left on the board. These will all be removed in pairs and replaced by 0 's. The difference between the 0 's will be 0 's, so the last number on the board will be 0 .

If $n$ is three more than a multiple of 4 , all the original numbers except 2023 will have been replaced by an odd number of 1's left on the board. Whenever the board contains a number of 1 's and a larger number, $k$, the larger number, $k$, and a 1 are replaced by $k-1$ until there are only 1's left or there is only one number left. If $n<4047$, there will be fewer than 2023 l's left on the board with 2023, so there will be one number greater than 1 left on the board when all the 1's have been removed. If $n \geq 4047$, there will be at least 2023 l's left with 2023, so the board will get down to only 1's. As explained above, the last number must be even and cannot be greater than 1 , so it must end with a 0 .

The possible values of $n$ are all multiples of 4 and all numbers at least 4047 which are three more than a multiple of 4 .