[Math] How many numbers between 0 and 1,000 have the sum of their digits equal to 15 or less

combinatorics

How many numbers between 0 and 1,000 have the sum of their digits equal to 15 or less?

I went about this a rather long route looking case by case and I noticed a pattern. Between 0 and 99 I found 5 cases that didn't work, between 100 and 199 10 cases that didn't work, between 200 and 299 15 cases that didn't work… etc

I got my final answer to be 725. Can someone confirm my solution?

Best Answer

Clearly, $1000$ has digit sum less than $15$.

By appending leading zeros as necessary, we can represent any nonnegative integer less than $1000$ as a three-digit string. For instance, we can represent $17$ as $017$. Notice that appending leading zeros does not change the digit sum.

Let $d_k$ be the $k$th digit. Then we want to find the number of solutions of the inequality $$d_1 + d_2 + d_3 \leq 15$$ in the nonnegative integers subject to the restrictions that $d_1, d_2, d_3 \leq 9$. We can transform the inequality into an equation with the same number of solutions. Let $$s = 15 - (d_1 + d_2 + d_3)$$ Then $s$ is a nonnegative integer and $$d_1 + d_2 + d_3 + s = 15 \tag{1}$$ Equation 1 is an equation in the nonnegative integers. A particular solution of equation 1 corresponds to the placement of three addition signs in a row of $15$ ones. For instance, $$1 1 1 1 + 1 1 1 1 1 1 + 1 1 1 + 1 1$$ corresponds to the solution $d_1 = 4$, $d_2 = 6$, $d_3 = 3$, $s = 2$, while $$+ 1 1 1 1 1 1 1 1 1 + 1 1 + 1 1 1 1$$ corresponds to the solution $d_1 = 0$, $d_2 = 9$, $d_3 = 2$, $s = 4$. The number of solutions of equation 1 is $$\binom{15 + 3}{3} = \binom{18}{3}$$ since we must select which three of the eighteen positions required for fifteen ones and three addition signs will be filled with addition signs.

However, these solutions include those in which one of the variables $d_1$, $d_2$, or $d_3$ exceeds $9$ (we do not care if $s > 9$ since it does not represent a digit). Notice that at most one variable can exceed $9$ since $2 \cdot 10 = 20 > 15$.

Suppose $d_1 > 9$. Then $d_1' = d_1 - 10$ is a nonnegative integer. Substituting $d_1' + 10$ for $d_1$ in equation 1 gives \begin{align*} d_1' + 10 + d_2 + d_3 + s & = 15\\ d_1 + d_2 + d_3 + s & = 5 \tag{2} \end{align*} Equation 2 is an equation in the nonnegative integers with $$\binom{5 + 3}{3} = \binom{8}{3}$$ solutions. By symmetry, there are an equal number of solutions of equation 1 in which $d_2 > 9$ or $d_3 > 9$. Hence, the number of solutions of equation 1 that violate the restrictions $d_1, d_2, d_3 \leq 9$ is $$\binom{3}{1}\binom{8}{3}$$ Therefore, the number of nonnegative integers less than $1000$ that have digit sum at most $15$ is $$\binom{18}{3} - \binom{3}{1}\binom{8}{3}$$ so the number of nonnegative integers that are at most $1000$ that have digit sum at most $15$ is $$\binom{18}{3} - \binom{3}{1}\binom{8}{3} + 1 = 649$$ Your proposed answer of $725$ suggests that you did not take into account the fact that the leading digit of a two-digit or three-digit number (as opposed to string) cannot be zero.