I would like to calculate the number of integral solutions to the equation
$$x_1 + x_2 + \cdots + x_n = k$$
where
$$a_1 \le x_1 \le b_1, a_2 \le x_2 \le b_2, a_3 \le x_3 \le b_3$$
and so on.
How do we approach problems with variables constrained on both sides $(a_1 \le x_1 \le b_1)$ or with constraints like $x_1 \le b_1$?
I know that the same equation with constraints like $x_1 \ge a_1, x_2 \ge a_2$ and so on can be solved using a slight modification of the formula $\binom{n + k - 1}{ k}$. Is it possible to tweak the same formula to suit the given problem?