# 2007 AMC 12A Problems/Problem 22

The following problem is from both the 2007 AMC 12A #22 and 2007 AMC 10A #25, so both problems redirect to this page.

## 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

### Solution 1

For the sake of notation let $T(n) = n + S(n) + S(S(n))$. Obviously $n<2007$. Then the maximum value of $S(n) + S(S(n))$ is when $n = 1999$, and the sum becomes $28 + 10 = 38$. So the minimum bound is $1969$. We do casework upon the tens digit:

Case 1: $196u \Longrightarrow u = 9$. Easy to directly disprove.

Case 2: $197u$. $S(n) = 1 + 9 + 7 + u = 17 + u$, and $S(S(n)) = 8+u$ if $u \le 2$ and $S(S(n)) = 2 + (u-3) = u-1$ otherwise.

Subcase a: $T(n) = 1970 + u + 17 + u + 8 + u = 1995 + 3u = 2007 \Longrightarrow u = 4$. This exceeds our bounds, so no solution here.
Subcase b: $T(n) = 1970 + u + 17 + u + u - 1 = 1986 + 3u = 2007 \Longrightarrow u = 7$. First solution.

Case 3: $198u$. $S(n) = 18 + u$, and $S(S(n)) = 9 + u$ if $u \le 1$ and $2 + (u-2) = u$ otherwise.

Subcase a: $T(n) = 1980 + u + 18 + u + 9 + u = 2007 + 3u = 2007 \Longrightarrow u = 0$. Second solution.
Subcase b: $T(n) = 1980 + u + 18 + u + u = 1998 + 3u = 2007 \Longrightarrow u = 3$. Third solution.

Case 4: $199u$. But $S(n) > 19$, and $n + S(n)$ clearly sum to $> 2007$.

Case 5: $200u$. So $S(n) = 2 + u$ and $S(S(n)) = 2 + u$ (recall that $n < 2007$), and $2000 + u + 2 + u + 2 + u = 2004 + 3u = 2007 \Longrightarrow u = 1$. Fourth solution.

In total we have $4 \mathrm{(D)}$ solutions, which are $1977, 1980, 1983,$ and $2001$.

### Solution 2

Clearly, $n > 1950$. We can break this into three cases:

Case 1: $n \geq 2000$

Inspection gives $n = 2001$.

Case 2: $n < 2000$, $n = 19xy$(not to be confused with $19*x*y$), $x + y < 10$

If you set up an equation, it reduces to

$4x + y = 32$

which has as its only solution satisfying the constraints $x = 8$, $y = 0$.

Case 3: $n < 2000$, $n = 19xy$, $x + y \geq 10$

This reduces to
$4x + y = 35$. The only two solutions satisfying the constraints for this equation are $x = 7$, $y = 7$ and $x = 8$, $y = 3$.

The solutions are thus $1977, 1980, 1983, 2001$ and the answer is $\mathrm{(D)}\ 4$.

### Solution 3

As in Solution 1, we note that $S(n)\leq 28$ and $S(S(n))\leq 10$.
Obviously, $n\equiv S(n)\equiv S(S(n)) \pmod 9$.
As $2007\equiv 0 \pmod 9$, this means that $n\bmod 9 \in\{0,3,6\}$, or equivalently that $n\equiv S(n)\equiv S(S(n))\equiv 0 \pmod 3$.

Thus $S(S(n))\in\{3,6,9\}$. For each possible $S(S(n))$ we get three possible $S(n)$.
(E. g., if $S(S(n))=6$, then $S(n)=x$ is a number such that $x\leq 28$ and $S(x)=6$, therefore $S(n)\in\{6,15,24\}$.)

For each of these nine possibilities we compute $n_{?}$ as $2007-S(n)-S(S(n))$ and check whether $S(n_{?})=S(n)$.
We'll find out that out of the 9 cases, in 4 the value $n_{?}$ has the correct sum of digits.
This happens for $n_{?}\in \{ 1977, 1980, 1983, 2001 \}$.

### Solution 4 (PYTHON!)

This is mainly for fun. We can create a python program to do this for us:

 def calculateSumOfDigits(number): 

 number = str(number)  digits = []  for i in range(len(number)):  digits.append(int(number[i]))  return sum(digits) for i in range(2007):  if(i+calculateSumOfDigits(i)+calculateSumOfDigits(calculateSumOfDigits(i)) == 2007):  print(i)