I am trying to derive a closed form for computing the number possible outcomes of rolling $k$ dices such that the sum is $n$.


This seems to be the problem of finding number of positive integral solution of an equation $$x\_1+x\_2+\cdots+x\_k=n$$ with $x\_1,x\_2,\cdots,x\_n \in [1,6] $,but here a solution $(a,a,a,a,\cdots \text { k-times} )$ is not considered different.


Direct application of [stars and bars](http://en.wikipedia.org/wiki/Stars_and_bars_(combinatorics)) gives a closed form $\binom{n-1}{2} \times k \binom{n-7}{2}$ but this is not working for all the cases, For example the case of $n=16$ and $k=3$,what exactly should I modify in my approach?


[Similar (but particular) question in M.SE](https://math.stackexchange.com/questions/68045/rolling-dice-such-that-they-add-up-to-13-is-there-a-more-elegant-way-to-solve/). 



Deriving a closed form for rolling a sum $n$ with $k$ dice using stars and bars
Answer is given by the coefficient of $z^n$ in 
$$(z+z^2+\dots+z^6)^k = \left(z\frac{1-z^6}{1-z}\right)^k = z^k (1-z^6)^k(1-z)^{-k}.$$
An explicit formula for this coefficient is:
$$\sum\_{i=0}^{\min(k,\lfloor (n-k)/6\rfloor)} (-1)^{n+i} \binom{k}{i} \binom{-k}{n-k-6i} = \sum\_{i=0}^{\min(k,\lfloor (n-k)/6\rfloor)} (-1)^i \binom{k}{i} \binom{n-6i-1}{k-1}.$$


