This is asking you to find the number of ways to write b
as a sum of n
positive integers. The answer is the number of compositions of b
into n
parts, which is (b-1 choose n-1)
.
Now if we take into account the constraint that the size of the parts is limited to a
, the problem gets a little more interesting. I recommend using generating functions for this. The answer will be the coefficient of x^b
in the product (x+x^2+...+x^a)^n
. Why? Because for each die (the singular of dice), you have a number between 1
and a
, and this is represented by the exponent of x
. When you take one x^i
from each of the n
terms, this is equivalent to the number i
coming up on that die. The sum of the exponents must be the sum you are after, namely b
.
We can even simplify the problem a bit using the multinomial theorem which states:
(x + x^2 + ... + x^a)^n = sum_{k1+k2+...+ka=n} (n multichoose k1,k2,...,ka) x^{k1+2*k2+...+a*ka}
where all ki >= 0
. So the answer is that the number of ways is
sum_{k1+k2+...+ka=n & k1+2*k2+...+a*ka=b} (n multichoose k1,k2,...,ka)