# 2016 AMC 12A Problems/Problem 25

## Problem

Let be a positive integer. Bernardo and Silvia take turns writing and erasing numbers on a blackboard as follows: Bernardo starts by writing the smallest perfect square with k+1 digits. Every time Bernardo writes a number, Silvia erases the last k digits of it. Bernardo then writes the next perfect square, Silvia erases the last k digits of it, and this process continues until the last two numbers that remain on the board differ by at least 2. Let f(k) be the smallest positive integer not written on the board. For example, if k = 1, then the numbers that Bernardo writes are , and the numbers showing on the board after Silvia erases are 1, 2, 3, 4, and 6, and thus f(1) = 5. What is the sum of the digits of ?

## Solution

Consider . The numbers left on the blackboard will show the hundreds place at the end. In order for the hundreds place to differ by 2, the difference between two perfect squares needs to be at least . Calculus and a bit of thinking says this first happens at . The perfect squares from here go: . Note that the ones and tens also make the perfect squares, . After the ones and tens make , the hundreds place will go up by , thus reaching our goal. Since , the last perfect square to be written will be . The missing number is one less than the number of hundreds of , or .

Now consider f(4). Instead of the difference between two squares needing to be , the difference must now be . This first happens at . After this point, similarly, more numbers are needed to make the th's place go up by . This will take place at . Removing the last four digits (the zeros) and subtracting one yields for the skipped value.

In general, each new value of f will add two digits to the "" and one digit to the "". This means that the last number Bernardo writes for is , the last for will be , and so on until . Removing the last digits as Silvia does will be the same as removing trailing zeroes on the number to be squared. This means that the last number on the board for is , is , and so on. So the first missing number is ,, etc. The squaring will make a "" with two more digits than the last number, a "" with one more digit, and a "". The missing number is one less than that, so the "1" will be subtracted from . In other words, .

Therefore:

And so on. The sum is:

+ , with repetitions each of "" and "". There is no carrying in this addition. Therefore each adds to the sum of the digits. Since , , and , or .