# Evaluation of the sum $\sum_\limits{a=1}^{p-1} \left\lfloor \frac{\left\lfloor{v/p}\right\rfloor+a}{q}\right\rfloor$

Looking for the evaluation of the sum $$\sum_{a=1}^{p-1} \left\lfloor \frac{\left\lfloor{v/p}\right\rfloor+a}{q}\right\rfloor$$ where $p < q$, $p$ and $q$ are primes, and $v = (N \mod{p*q})$ where for integer $N \ge p * q$. Also $\left\lfloor{v/p}\right\rfloor \in \left\{{0, 1, 2, \ldots, q - 1}\right\}$.

A partial answer is I think $\left\lfloor{v/p}\right\rfloor$ plus some other terms. Now I have established that $$\sum_{a=1}^{q-1} \left\lfloor \frac{\left\lfloor{v/p}\right\rfloor+a}{q}\right\rfloor = \left\lfloor{v/p}\right\rfloor.$$

The primeness of $p$ and $q$ may not be required for the proof.

Since $v < pq$, we have $\lfloor v/p \rfloor + a <2q$ for $a\leq p \leq q$, so each term is either $0$ or $1$.
A term is $1$ iff $a$ is large enough: one needs $a \geq q-\lfloor v/p\rfloor$.
So the sum is the number of integers in the interval $\left[ q-\lfloor v/p\rfloor, p-1 \right]$, which is $$\max(0, p-q+\lfloor v/p\rfloor)$$ This holds for any positive integers $p\leq q$.