How many positive integer solutions of $$\sum\_{i=1}^{k}x\_i = N$$ for some positive integer $N$ given the constraints $n\_i\leq x\_i\leq m\_i$ for $i=1,\ldots,k$, where $n\_i$ and $m\_i$ are positive integers.


I know that it can be calculated by finding the coefficient of $y^N$ in the polynomial $\prod\_{i=1}^{K}(y^{n\_i}+\cdots,y^{m\_{i}})$. Is there any compact formula or any upper bound to the number of the positive integer solutions?



Number of integer solutions of a linear equation under constraints

> 
> **Proposition 1:** The number of integer solutions of the equation 
>  $$
> \sum\_{i=1}^{k}x\_i = N
> $$
>  where $x\_i\geq n\_i$ for $i=1,\ldots,k$, is given by 
>  $$
> {\small
> \binom{N+k-1-n\_1-n\_2-...-n\_k}{k-1}
> }
> $$
>  if the upper index is non-negative and zero otherwise. 
> 
> 
> 


In the formula above, $\binom{.}{.}$ stands for the [generalized binomial coefficients](https://en.wikipedia.org/wiki/Binomial_coefficient). 


Now, to tackle the problem as stated, you need to apply Proposition 1 and invoke the [inclusion-exclusion principle](https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle), in the following sense:


For $i=1,...,k$, set as 



> 
> $q\_i$: the property of a solution of Proposition 1, to satisfy the condition 
>  $$
> x\_i> m\_i \Leftrightarrow x\_i\geq m\_i+1
> $$
> 
> 
> 


If we denote: 


* $N(q\_i)$, the number of solutions (provided by Prop. 1) satisfying property $q\_i$,
* $N(q\_i q\_j)$, the number of solutions (provided by Prop. 1) satisfying both properties $q\_i$, $q\_j$,


... and generally: 


* $N(q\_{i\_1}q\_{i\_2}... q\_{i\_s})$, the number of solutions (provided by Prop. 1) satisfying all properties $q\_{i\_1}$, $q\_{i\_2}$, ..., $q\_{i\_s}$,


then we get -applying Prop. 1- that: 
$$
{\small
N(q\_1)=\binom{N+(k-1)-1-m\_1-n\_2-...-n\_k}{k-1} \ \ \ or \ \ \ N(q\_1)=0
}
$$ 


$$ 
{\small
N(q\_2 q\_3)=\binom{N+(k-2)-1-n\_1-m\_2-m\_3-n\_4-...-n\_k}{k-1}
 \ \ \ or \ \ \ N(q\_2 q\_3)=0}
$$
... and generally:
$$
{\small
N(q\_{i\_1}q\_{i\_2}... q\_{i\_s})=\binom{N+(k-s)-1-\sum\_{i\notin I} n\_i-\sum\_{i\in I} m\_i}{k-1} \ \ \ or \ \ \ N(q\_{i\_1}q\_{i\_2}... q\_{i\_s})=0
}
$$ 
where $s$ is the number of properties, $I=\{i\_1, i\_2, ..., i\_s\}\subseteq \{1,2,...,k\}$ and the $N(..)$ function takes zero values whenever the upper index becomes negative. 


Now all you need to do to obtain a compact formula for the number of solutions satisfying your constraints, is to apply the inclusion-exclusion principle to determine the number of solutions produced by Proposition 1, **which have none** of the properties $q\_i$ for $i=1,2,...,k$.  

This is given by 



> 
> $$
> \binom{N+k-1-\sum n\_i}{k-1}-\sum\_{i=1}^{k} N(q\_i)+\sum\_{k\ \geq j > i\geq 1} N(q\_i q\_j)-...+ \\ +(-1)^s\sum\_{k\ \geq i\_s>...>i\_1\geq 1} N(q\_{i\_1}q\_{i\_2}... q\_{i\_s})+.... +(-1)^k N(q\_{1}q\_{2}... q\_{k}) 
> $$
> 
> 
> 


where in the above formula $s$ is the number of properties and 
$$
\sum\_{k\ \geq j > i \geq 1}=\sum\_{i=1}^{k-1}\sum\_{j=i+1}^{k}
$$ 
... etc.


**Example:** As an example of application of the previous method, consider the following special case of the OP: 



> 
> Find the number of (positive) integer solutions of the equation
>  $$\sum\_{i=1}^{k}x\_i = N$$ for some positive integer $N$, given the constraints $1\leq x\_i\leq \alpha$ for $i=1,\ldots,k$
> 
> 
> 


The method described above gives: 
$$
{\small
\binom{N-1}{k-1}-\binom{k}{1}\binom{N-\alpha-1}{k-1}+\binom{k}{2}\binom{N-2\alpha-1}{k-1}-\binom{k}{3}\binom{N-3\alpha-1}{k-1}+\binom{k}{4}\binom{N-4\alpha-1}{k-1}-\cdots
}
$$
where $\binom{..}{..}$ stands for the generalized binomial coefficients and the summation halts when zero terms appear.


