# If I have an integer, how many numbers are there whose digits sum to the integer?

Suppose I have an integer, $m$, and another integer, $n$, then is there a way of working out how many numbers of length $n$ exist such that the sum of their individual digits is $m$?

Another way of thinking of this is how many ways are there of placing $m$ balls in a row of n buckets such that the first bucket is not empty and no bucket has more than $9$ balls.

Is there an explicit function that takes in the arguements $m$ and $n$ and outputs the answer or will an algorithm have to be implemented?

• You're asking for the number of solutions of $x_1+x_2+\cdots+x_n=m$ subject to $0\le x_i\le9$ (well, it's a little more complicated than that, if you don't allow leading zeros, but that can be taken care of). That kind of question has been asked and answered here dozens of times. Have a look at the Related questions, or do a little search through the site. – Gerry Myerson Nov 19 '17 at 23:48