TITLE: Counting the numbers between $1$ and $1,000,000$ whose digits sum to $30$
QUESTION [5 upvotes]: What's the number of numbers between $1$ and $1,000,000$ whose digits sum is $30$?

So I thought of this as a stars and sticks problem, so in the case you have $35\choose 5$ numbers whose sum is $30$. But obviously this number of numbers includes many overlaps (if for instance the requested sum was $8$, then $80=800=8000=134=143=431$ etc.). How do I get rid of the overlaps (inclusion-exclusion)? 
Thanks in advance for any assistance!

REPLY [5 votes]: One looks for the number $N$ of integer solutions of
$$
\sum_{i=1}^6n_i=30,\qquad 0\leqslant n_i\leqslant9.
$$
Thus, $N$ is the coefficient of $x^{30}$ in the polynomial
$$
\prod_{i=1}^6\sum_{n_i=0}^9x^{n_i}=\left(\frac{1-x^{10}}{1-x}\right)^6.
$$
To compute $N$, note that
$$
(1-x^{10})^6=\color{red}{1}-\color{red}{6}x^{10}+\color{red}{15}x^{20}-\color{red}{20}x^{30}+o(30),
$$
and that
$$
\frac{1}{(1-x)^6}=\sum_{k=0}^{30}\color{green}{{5+k\choose5}}x^k+o(30),
$$
where $o(30)$ denotes terms of order at least $31$, hence
$$
N=\color{red}{1}\cdot\color{green}{{5+30\choose5}}-\color{red}{6}\cdot\color{green}{{5+20\choose5}}+\color{red}{15}\cdot\color{green}{{5+10\choose5}}-\color{red}{20}\cdot\color{green}{{5+0\choose5}}=50877.
$$