# Question from an IMC(International mathematics competition) key statge III selection exam

A positive integer n does not have any 9 digits, it has four 8 digits, three 7 digits, two 6 digits and some other digits. If the sum of the digits of the numbeer n is 104 andthe sum of the digits of the number 2*n is 100, find the number of times the digit 5 appears in n.

Guys, my thoughts about the question above, are that in order for the sum of the digits of 2*n to be less than the sum of the digits of n, there have to be many digits inside it, which are larger than or equal to 5. However, this thought, did not lead me to the solution of the problem.

Can you guys please help me complete my thoughts, or, if they are wrong, can you please show me the correct method, of solving, this problem?

If $$n$$ has digits $$d_j$$, $$j = 0 \ldots m$$, then $$2n$$ has digits $$e_j$$ where $$e_j + 10 c_j = 2 d_j + c_{j-1}$$, $$c_{j} = 0$$ or $$1$$ being the "carry" from position $$j$$. Adding these up for all $$j$$ tells us $$\sum_j e_j + 10 \sum_j c_j = 2 \sum_j d_j + \sum_j c_j$$, i.e. $$9 \sum_j c_j = 2 \sum_j d_j - \sum_j e_j$$. In your case, that is $$2 \cdot 104 - 100 = 108$$. Thus there are $$108/9 = 12$$ carries. A carry occurs whenever $$d_j = 5, 6, 7, 8$$, or $$9$$. But you know the number of $$6, 7, 8$$ and $$9$$...