Problem: For each positive integer $n$ , let $S(n)$ denote the sum of the digits of $n.$ For how many values of $n$ is $n + S(n) + S(S(n)) = 2007?$
$\mathrm{(A)}\ 1 \qquad \mathrm{(B)}\ 2 \qquad \mathrm{(C)}\ 3 \qquad \mathrm{(D)}\ 4 \qquad \mathrm{(E)}\ 5$

Solution: Let the number of digits of $n$ be $m$ . If $m = 5$ $n$ will already be greater than $2007$ . Notice that $S(n)$ is always at most $9m$ . Then if $m = 3$ $n$ will be at most $999$ $S(n)$ will be at most $27$ , and $S(S(n))$ will be even smaller than $27$ . Clearly we cannot reach a sum of $2007$ , unless $m = 4$ (i.e. $n$ has $4$ digits).
Then, let $n$ be a four digit number in the form $1000a + 100b + 10c + d$ . Then $S(n) = a + b + c + d$
$S(S(n))$ is the sum of the digits of $a + b + c + d$ . We can represent $S(S(n))$ as the sum of the tens digit and the ones digit of $S(n)$ . The tens digit in the form of a decimal is
$\frac{a + b + c + d}{10}$
To remove the decimal portion, we can simply take the floor of the expression,
$\lfloor\frac{a + b + c + d}{10}\rfloor$
Now that we have expressed the tens digit, we can express the ones digit as $S(n) -10$ times the above expression, or
$a + b + c + d - 10\lfloor\frac{a + b + c + d}{10}\rfloor$
Adding the two expressions yields the value of $S(S(n))$
$= a + b + c + d - 9\lfloor\frac{a + b + c + d}{10}\rfloor$
Combining this expression to the ones for $n$ and $S(n)$ yields
$1002a + 102b + 12c + 3d - 9\lfloor\frac{a + b + c + d}{10}\rfloor$
Setting this equal to $2007$ and rearranging a bit yields
$12c + 3d = 2007 - 1002a - 102b + 9\lfloor\frac{a + b + c + d}{10}\rfloor$
$\Rightarrow$ $4c + d = 669 - 334a - 34b + 3\lfloor\frac{a + b + c + d}{10}\rfloor$
(The reason for this slightly weird arrangement will soon become evident)
Now we examine the possible values of $a$ . If $a \ge 3$ $n$ is already too large. $a$ must also be greater than $0$ , or $n$ would be a $3$ -digit number. Therefore, $a = 1 \, \text{or} \, 2$ . Now we examine by case.
If $a = 2$ , then $b$ and $c$ must both be $0$ (otherwise $n$ would already be greater than $2007$ ). Substituting these values into the equation yields
$d = 1 + 3\lfloor\frac{2 + d}{10}\rfloor$
$\Rightarrow$ $d=1$
Sure enough, $2001 + (2+1) + 3=2007$
Now we move onto the case where $a = 1$ . Then our initial equation simplifies to
$4c + d = 335 - 34b + 3\lfloor\frac{1 + b + c + d}{10}\rfloor$
Since $c$ and $d$ can each be at most $9$ , we substitute that value to find the lower bound of $b$ . Doing so yields
$34b \ge 290 + 3\lfloor\frac{19 + b}{10}\rfloor$
The floor expression is at least $3\lfloor\frac{19}{10}\rfloor=3$ , so the right-hand side is at least $293$ . Solving for $b$ , we see that $b \ge 9$ $\Rightarrow$ $b=9$ . Again, we substitute for $b$ and the equation becomes
$4c + d = 29 + 3\lfloor\frac{10 + c + d}{10}\rfloor$
$\Rightarrow$ $4c + d = 32 + 3\lfloor\frac{c + d}{10}\rfloor$
Just like we did for $b$ , we can find the lower bound of $c$ by assuming $d = 9$ and solving:
$4c + 9 \ge 29 + 3\lfloor\frac{c + 9}{10}\rfloor$
$\Rightarrow$ $4c \ge 20 + 3\lfloor\frac{c + 9}{10}\rfloor$
The right hand side is $20$ for $c=0$ and $23$ for $c \ge 1$ . Solving for c yields $c \ge 6$ . Looking back at the previous equation, the floor expression is $0$ for $c+d \le 9$ and $3$ for $c+d \ge 10$ . Thus, the right-hand side is $32$ for $c+d \le 9$ and $35$ for $c+d \ge 10$ . We can solve these two scenarios as systems of equations/inequalities:
$4c+d = 32$
$c+d \le 9$
and
$4c+d=35$
$c+d \ge 10$
Solving yields three pairs $(c, d):$ $(8, 0)$ $(8, 3)$ ; and $(7, 7)$ . Checking the numbers $1980$ $1983$ , and $1977$ ; we find that all three work. Therefore there are a total of $4$ possibilities for $n$ $\Rightarrow$ $\boxed{4}$

Answer: D 4