Summation over k of Ceiling of mk+x over n

Theorem
Let $m, n \in \Z$ such that $n > 0$.

Let $x \in \R$.

Then:


 * $\displaystyle \sum_{0 \mathop \le k \mathop < n} \left \lceil{\dfrac {m k + x} n}\right \rceil = \dfrac {\left({m + 1}\right) \left({n - 1}\right)} 2 - \dfrac {d - 1} 2 + d \left \lceil{\dfrac x d}\right \rceil$

where:
 * $\left \lceil{x}\right \rceil$ denotes the ceiling of $x$
 * $d$ is the greatest common divisor of $m$ and $n$.