How many positive integers have less than $90000$ have the sum of their digits equal to $17$? How many positive integers have less than $90000$ have the sum of their digits equal to $17$?
I tried to write the number as $ABCDE$ and use some math with that (so we need $A + B + C + D + E = 17$), and I tried to use stars and bars, but I got no progress.
Can someone please help me?
 A: You need to find the number of solutions of $$A+B+C+D+E=17$$
where $0\leq A\leq 8$ and all other variables lie between $0$ and $9$. Check that it is coefficient of $x^{17}$ in the following expression:
$$(1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8)$$
$$\times(1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9)^4$$
Now, apply GP formula and simplify, i.e.
$$Expression = \frac{1-x^9}{1-x}\times\Big(\frac{1-x^{10}}{1-x}\Big)^4$$
$$ = \frac{(1-x^9)(1-x^{10})^4}{(1-x)^5}$$
Now, apply binomial expansion in $(1-x^{10})^4$ and ignore terms which don't contribute to term of $x^{17}$, we get,
$$\frac{(1-x^9)(1-4x^{10})}{(1-x)^5}$$
Now, you have terms with powers of $x$ as $0,9\&10$ in numerator, find the coefficients of $x^{17}, x^8\& x^7$ in the power series expansion of denominator using formula and you are done.
Hope it helps:)
A: Stars and bars sounds like a good idea.  You want to put $17$ balls in $5$ buckets, with no more than $9$ balls in any one bucket.  First do it without the $9$-ball restriction.  Now you have to subtract the number of ways that have $10$ or more balls in a bucket.  Since there are only $17$ balls, there can't be more than one bucket with $10$ balls.  Choose a bucket in which to place $10$ balls.  Now distribute the remaining $7$ balls in the $5$ buckets.
EDIT
I forgot about "less than $90000.$"  You also have to subtract the cases where there are exactly $9$ balls in the first bucket, so $8$ in the remaining $4$.
A: Not an answer, just hard to put in a comment. Python code.
c = 0
for i in range(1,90000):
    if sum(map(int,list(str(i))))==17:
        c += 1
print c 

