# Sequence where the sum of digits of all numbers is 7

BdMO 2014

We define a sequence starting with $a_1=7,a_2=16,\ldots,\,$ such that the sum of digits of all numbers of the sequence is $7$ and if $m>n$,then $a_m>a_n$ i.e. all such numbers are arranged in ascending order. If $a_k=2014$, find $a_{\frac{k}{2}+3}$.

Let us call the numbers of the sequence 'good'.Then there are 1 one-digit good number,7 two-digit good numbers, 28 three-digit good numbers,and (28 four digit good numbers that start with 1). Total$=64$. Then 2014 is the 66th number.Therefore we want $a_{36}$. We note that there are 36 good numbers from 1 to 999. So the 36th good number is the largest 3 digit good number, i.e. 700.

Is there a better way?The above method clearly is a practical way of doing it,but is there a smarter way?

-
I don't think there is a better way, but I'd like to be surprised, – vonbrand Feb 3 '14 at 4:33
@vonbrand,the reason I think there is a better way is because a person who was in charge of checking answers told me so.But I too cannot see a neater way. – rah4927 Feb 3 '14 at 4:37
@rah4927 what is being asked for? I cant see the subscript clearly. – Sandeep Thilakan Feb 3 '14 at 4:39
@rah4927 then you are required to find $a_{24}$. Isnt it? – Sandeep Thilakan Feb 3 '14 at 4:50
I do not think that the problem is clearly stated... it is not written anywhere that your sequence contains ALL numbers whose sum of the digits is 7... – Simone Feb 3 '14 at 11:06

To find the number of terms having less than 4 digits, consider $x_1x_2x_3$ with the condition that $x_1 + x_2 + x_3 = 7$ and $x_1 \geq 0, x_2 \geq 0, x_3 \geq 0$. This is a standard combinatorics problem with number of solutions $= \binom{9}{7} = 36$
Next, we need to find the number of 4-digit terms with the first digit equal to $1$. So, consider $1x_1x_2x_3$ with $x_1 + x_2 + x_3 = 6$ and a similar analysis gives the number of solutions $= \binom{8}{6} = 28$.
Then $2005$ happens to be the $36 + 28 + 1 = 65$th term and hence $2014$ is the $66$th. The rest is same as explained by @rah4927.