Question involving sum of digits Let $S(M)$ denote the sum of the digits of a positive integer $M$ written in
base $10$. Let $N$ be the smallest positive integer such that $S(N) = 2013$.
What is the value of $S(5N + 2013)$?
I came across this question. After almost $20$ mins, I got the answer to be $18$. Am I correct?
 A: I got $18$ too. I suppose that you got that $M$ can be written, in base $10$, as a $6$ followed by $223$ $9$'s.
More details: Since $2013=223\times9+6$, it is easy to see that $M$ is, as I wrote, the number that can be written, in base $10$, as a $6$ followed by $223$ $9$'s. Now, how to write $5M$ in base $10$? Note that$$5\times\overbrace{99\cdots99}^{\text{$n$ times}}=5\times(10^n-1)=5\times10^n-5=4\overbrace{99\cdots99}^{\text{$n-1$ times}}5.$$So$$5M=34\overbrace{99\cdots99}^{\text{$222$ times}}5$$and therefore, since $2\,013+9\,995=12\,008$,$$5M+2013=35\overbrace{00\dots00}^{\text{$219$ times}}2008.$$Finally, $S(5M+2013)=3+5+2+8=18.$
A: $N=6\times 10^{223}+10^{223}-1$ 
is the smallest number such that $S(N)=2013$
Let $5N=30\times 10^{223} +5\times 10^{223} -5$ 
we have $S(5N)=2010$, but if we add $2013$ we get
$5N+2013=30\times 10^{223} +5\times 10^{223} +2008$
and $S(N)=3+5+2+8=18$
hope this helps
A: Since number with $n$ digits can have sum of digits at most $9n$, if you are looking for number with sum of digits equal to some value $k$, you need at least $\lceil \frac k 9 \rceil $ digits and let that be equal to $n+1$. The least such number with n+1 digits would be the one with the least leading digit, so in order to minimize the leading digit, we need to maximize the tailing n digits. But we already know that is the case of "all digits are 9" number. So in general, the least number having a certain sum of digits is:
$$((k \; mod\;9) \cdot 10 ^{\lfloor \frac k 9 \rfloor}+10^{\lfloor \frac k 9 \rfloor}-1 $$
Knowing this, the rest is easy to do (or rather others have already done that)
