What’s the sum of all possible values of a number which is the sum of the digits of another number in this question

arithmeticcombinatorics

I came across a question in an exercise booklet for Mathematic Olympiad for primary school students in Australia. The question is described as follows:

Let A be a 2018-digit number which is divisible by 9. Let B be the sum of all digits of A and C be the sum of all digits of B Find the sum of all possible values of C.

I could put the above question into algebraic formulae, but I still couldn't work out the solution. I find it hard to tackle the different possibilities of the number C. Can anyone please help solve this problem? Thank you very much.

Best Answer

First say if $A = 999 \cdots 999$, then $B = 2018 \cdot 9 = 18162$. And this $B$ has the max value possible given $A$ only has $2018$ digits and is divisible by $9$.

Notice if $B$ has $5$ digits, then $C$ at most can only be $35$ (e.g. $B = 17999 \Leftarrow A$ has $1999$ digits of $9$, $1$ digit of $8$ and $18$ digits of $0$), but not $36$ (e.g. $B = 18999$).

Next if $B$ has $4$ digits, then max of $B = 9999$ is possible when $A$ has $1111$ digits of $9$, other digits $0$, so $C = 36$. Quite clearly $37$ or above is impossible if we further reduce the value of $B$.

Also for $A$ to be a $2018$ digit no., $\min B = 9$ $(e.g. A = 10,000, \cdots ,008) \Rightarrow \min C = 9$.

Thus $C$ ranges from $9$ to $36$. The required sum is $45 \cdot 14 = 630$.

[Edit: I missed the fact that divisible by $9$ $\Leftrightarrow$ sum of digits must be multiples of $9$. Hence the required sum should be smaller than from $1$ to $36$.]