I need to find the amount of numbers between $1$ and $10^k$ (k-digits number) that their digits sum is not more than $r$.
I saw some questions solving similar problems, using generating functions, all of them used the generating function of the form: $F(x)=x+x^2+x^3...+x^9$.
I wonder how is it relevant to this question? How can I use it to solve this?
Many thanks!
Yeah, that should work out fine for you (after a few corrections).
The basic idea is that you can create a correspondence between the number $1089$ and the term $x^1x^0x^8x^9$ and if you iterated over a range of numbers the coefficient of $x^{18}$ in your sum would be the number of integers in that range that had a digit sum of $18$.
In your case, you want to calculate $$\prod_{n=1}^k(1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9)$$ and then add all of the coefficients up through $x^r$. Note that you want to include a term of $1$ because that corresponds to a digit of $0$ in the numbers you are considering.