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.

Partial solution:
We can break the expression into four parts $E_1 + E_2 + E_3 + E_4$
where $$E_1 = \sum_{\substack{0\le n\le N/2 \\ 0\le m\le M/2}}(MN -mN-nM) = $$
$$E_2 = \sum_{\substack{0\le n\le N/2 \\ M/2\le m\le M}}|MN -mN-nM|$$
$$E_3 = \sum_{\substack{N/2\le n\le N \\ 0\le m\le M/2}}|MN -mN-nM|$$
$$E_4 = \sum_{\substack{N/2\le n\le N \\ M/2\le m\le M}}(mN + nM - MN) = \sum_{\substack{0\le n\le N/2 \\ 0\le m\le M/2}}(mN + nM)$$
$E_1 + E_4 = M^2N^2/4$
Both $E_2$ and $E_3$ can be rewritten as 
$$ E_2 = E_3 = \sum_{\substack{0\le n\le N/2 \\ 0\le m\le M/2}}|MN/2 -mN-nM|$$
so $$E_2 + E_3 = \sum_{\substack{0\le n\le N/2 \\ 0\le m\le M/2}}|MN -2mN-2nM|$$
So $$LHS = M^2N^2/4 + \sum_{\substack{0\le n\le N/2 \\ 0\le m\le M/2}}|MN -2mN-2nM|$$ 
and may be we can recursively move forward?
