Number of solutions for $x_1+ x_2+ x_3 + \cdots + x_k=n$, where $0\leq x_i\leq p$ for all $i$ I know that for $1\leq x_i\leq p$ the answer will be the coefficient of $x^n$  in $(x + x^2 + x^3 + ... + x^p)^k$. But what will be the answer for the constraint $0 \leq x_i \leq p?$ 
Also, how can I generate a definite formula or recurrence relation to program it? It will be difficult to calculate the answer by summing up the GP series and then calculating the coefficients using series expansion. 
Thank you!

For any fixed $p,k$ you look at the generating function $((1-x^{p+1})/(1-x))^k$ and the coefficient of $x^n$ is the answer $a(n)$. The generating function factors as $(1-x^{p+1})^k (1-x)^{-k}$ and each of these involves binomial coefficients. Thus the product coefficients is given by a sum involving products of binomial coefficients. $$a(n) = \sum_{i=0}^{\left\lfloor(n+1)/(p+1)\right\rfloor} (-1)^i {k \choose i} {n-(p+1)i+k-1 \choose k-1}.$$
