Finding a closed form for $\sum\limits_{\substack{0\le n\le N\\0\le m\le M}}\left|nM-Nm\right|$ I am trying to figure out if there is a closed form for the following sum:
$$
\sum_{\substack{0\le n\le N \\ 0\le m\le M}}\left|(N-n)(M-m)-nm\right|=\sum_{\substack{0\le n\le N \\ 0\le m\le M}}\left|nM-Nm\right|.
$$
Clearly, from symmetry, if we remove the absolute values, the sum evaulates to $0$.
Using the symmetry, I tried to evaluate the sum as
$$
2\cdot\sum_{\substack{0\le n\le N \\ 0\le m\le M \\ (N-n)(M-m)\gt nm}}\left((N-n)(M-m)-nm\right).
$$
However, that expression ended up containing sums of floor functions, for which I did not know a closed form.
Is there another way to obtain a closed form for the above sum?

Edit: If no closed form can be provided an efficient algorithm to compute the above sum given $N,M$ would also be good.

Edit 2: Since the time I have placed the bounty, I was able to find a closed form for the sum:

$$\frac{1}{6}\left[MN(2 M N + 3 (M + N + 1)) + M^2 + N^2-\gcd(M,N)^2\right].$$

So now I change the question to a challange: derive the above form from the sum. The prettiest derivation (if there are any) will get the bounty.

Hint:
The problem is governed by the solutions of $Mn=Nm$, the main diagonal of the rectangle. WLOG $M\ge N$ and let us assume for now that $M,N$ are relative primes, so that equality only occurs at the corners.
By symmetry, we just look below the diagonal and for a given $m$,
$$0\le n\le\left\lfloor{\frac{Nm}M}\right\rfloor=\left\lfloor{Qm}\right\rfloor.$$
Then, 
$$S:=\sum_{m=0}^{M-1}\sum_{n=0}^{\left\lfloor{Qm}\right\rfloor}(Nm-Mn)=M\sum_{m=0}^{M-1}\sum_{n=0}^{\left\lfloor{Qm}\right\rfloor}(Qm-n)\\
=M\sum_{m=0}^{M-1}\left(Qm-\frac12\left\lfloor{Qm}\right\rfloor\right)\left(\left\lfloor{Qm}\right\rfloor+1\right)\\
=\frac M2\sum_{m=0}^{M-1}\left(Qm+\{Qm\}\right)\left(Qm-\{Qm\}+1\right)\\
=\frac M2\sum_{m=0}^{M-1}\left((Qm)^2+Qm-\{Qm\}^2+\{Qm\}\right).$$ 
As in the sums of fractional parts, all fractions from $0/M$ to $(M-1)/M$ appear (in disorder),
$$12S=6M\left(Q^2\frac{(M-1)M(2M-1)}6+Q\frac{(M-1)M}2-\frac{(M-1)M(2M-1)}{6M^2}+\frac{(M-1)M}{2M}\right)\\
=2M^2N^2+M^2-3MN^2-3MN+N^2+3NM^2-1.$$
To this, we need to add the omitted term ($m=M$), which is found to be
$$T:=\sum_{n=0}^{N}(NM-Mn)=\frac{MN(N+1)}2,$$
and finally
$$2(S+T)=\frac{2M^2N^2+M^2+9MN^2+9MN+N^2+3NM^2-1}6.$$
Now if $M,N$ are not relative primes, one may split the summation in $G=\gcd(M,N)$ subsums of $\dfrac MG$ terms and a final $M^{th}$ term. This amounts to replacing the final $-1$ by $-G^2$.
