Example 3. Write the numbers , 1986, 1987 on the blackboard. At each step, determine some numbers from those written and erase them, replacing them with the remainder of their sum divided by 7. After several steps, two numbers remain on the blackboard, one of which is 987. What is the second remaining number?
(13th All-Russian Mathematics Competition, 1987)
Problem 663
Official solution
Solution: Clearly, at each step, the sum of all the numbers written down modulo 7 is preserved.
Let the remaining number be , then is congruent to modulo 7.
Since is divisible by 7, the remainder is 0, so is also divisible by 7. Since 987 is not the remainder when divided by 7, is the remainder of the operation when divided by 7, . Since 987 is divisible by 7,
thus .