Prove an Elementary sum of floor function Prove:
If $a$ and $b$ are odd and relatively prime,
$$\sum_{\substack{0 \lt x \lt b/2\\x \in Z}} \left\lfloor \frac{ax}{b} \right\rfloor + \sum_{\substack{0 \lt y \lt a/2\\y\in Z}} \left\lfloor \frac{by}{a} \right\rfloor = \frac{a-1}{2} \cdot \frac{b-1}{2}$$
I have already proved that if $a$ and $b$ are relatively prime, $\sum_{x=0}^{b-1} \left\lfloor \frac{ax}{b} \right\rfloor = \frac{(a-1)(b-1)}{2}$. My thinking was to possibly use this fact, and split this equation into 2 equations according to the separate variables and intervals. However, I am not sure how to split the equation into $a$ and $b$, so I'm lost on how to approach this problem.
Any help would be appreciated.
 A: Let's derive a more general formula. For arbitrary positive integers $a,b$, consider $$\newcommand{bigfloor}[1]{\left\lfloor #1\right\rfloor}S=\{(x,y)\in\mathbb{Z}^2 : 0<x<b/2, 0<y<a/2\},\\S_\geqslant=\{(x,y)\in S : ax\geqslant by\},\\S_\leqslant=\{(x,y)\in S : ax\leqslant by\},\\S_==\{(x,y)\in S : ax=by\}.$$
Now, for $(x,y)\in S$, we have $ax\geqslant by\iff y\leqslant ax/b\iff y\leqslant\lfloor ax/b\rfloor$, thus the first sum $\sum\limits_{0<x<b/2}\lfloor ax/b\rfloor$ is exactly $|S_\geqslant|$, the number of elements of $S_\geqslant$. Likewise $\sum\limits_{0<y<a/2}\lfloor by/a\rfloor=|S_\leqslant|$.
Further, $$|S_\geqslant|+|S_\leqslant|=|S_\geqslant\cup S_\leqslant|+|S_\geqslant\cap S_\leqslant|=|S|+|S_=|,$$ and trivially $|S|=\lfloor(a-1)/2\rfloor\cdot\lfloor(b-1)/2\rfloor$. So, it remains to count up $|S_=|$.
But if $d=\gcd(a,b)$, then $ax=by$ holds for positive integers $x,y$ if and only if $x=bc/d$ and $y=ac/d$ for a positive integer $c$ (to recall why: if $(a/d)x=(b/d)y$, then $a/d$ divides $(b/d)y$, hence $a/d$ divides $y$ because $a/d$ and $b/d$ are relatively prime; similarly, $b/d$ divides $x$, which gives the "only if"; the "if" is trivial). For $(x,y)\in S_=$, we should have additionally $c<d/2$. Thus, $|S_=|=\lfloor(d-1)/2\rfloor$, and finally $$\sum_{\substack{0<x<b/2\\x\in\mathbb{Z}}}\bigfloor{\frac{ax}{b}}+\sum_{\substack{0<y<a/2\\y\in\mathbb{Z}}}\bigfloor{\frac{by}{a}}=\bigfloor{\frac{a-1}{2}}\bigfloor{\frac{b-1}{2}}+\bigfloor{\frac{\gcd(a,b)-1}{2}}.$$
