Given two integers $x$ and $y$, each with lower and upper bounds ($x_{lb} \leq x \leq x_{ub}$ and $y_{lb} \leq y \leq y_{ub}$), count how many pairs have sum between $s_{lb}$ and $s_{ub}$.
Of course we can first optimise the bounds on the sum: $$\max(x_{lb} + y_{lb}, s_{lb}) \leq s \leq \min(x_{ub} + y_{ub}, s_{ub})$$
Let's take a concrete example: $-3 \leq x \leq 35$, $-4 \leq y \leq 42$ and we want $3 \leq x + y \leq 15$. From here, I have tried to isolate $y$: $$3 - x \leq y \leq 15 - x$$
But then follow many individual cases that may or may not apply, depending on the length of the intervals of $x$ and $y$.
I intend to programmatically count the number of solutions, in constant time (of course iterating through all values of $x$ would have been significantly easier).
To make things a bit easier we can assume $x_{lb} = 0$ and $y_{lb} = 0$ by adding constants to $x$ and $y$. In your example, let $u = x + 3, v = y + 4$. Then you want to count integer solutions to
$$0 \le u \le 38, 0 \le v \le 42, 3 \le (u - 3) + (v - 4) \le 15$$
or
$$ 0 \le u \le 38, 0 \le v \le 42, 10 \le u + v \le 22 $$
In this case only the lower bounds matter - so how many solutions to $10 \le u + v \le 22$ are there where $u$ and $v$ are non-negative integers? The easiest way to do this is to notice that there are
So there are $11 + 12 + \cdots + 23$ solutions. There is a well-known formula for the sum of an arithmetic progression like this - it's the number of terms, in this case $23 - 11 + 1 = 13$, times the average term, in this case $(11 + 23)/2 = 17$, for $13 \times 17 = 221$. So by knowing this formula you can do it in constant time.
The different cases depending on the length of the intervals are, I think, unavoidable.