Let $f$ be a $1$-periodic function (like $e^{2\pi ix}$). How can I evaluate a sum like $$\sum _{x=1}^{q}\sum _{y=1}^rf\left (\frac {x}{q}+\frac {y}{r}\right )$$ if $q,r$ are not coprime?
If they're coprime then the sum is $$\sum _{X=1}^{qr}f\left (\frac {X}{qr}\right )\sum _{x=1}^q\sum _{y=1\atop {xr+yq\equiv X(qr)}}^r1$$ and the congruence here is equivalent to $$X\equiv xr(q)\hspace {5mm}X\equiv yq(r)$$ which means there's only one choice for $x,y$ and the whole sum becomes $$\sum _{X=1}^{qr}f\left (\frac {X}{qr}\right ).$$
This is of course the Chinese Remainder Theorem and a version exists for non co-prime moduli in the form $$``X\equiv x(q)\hspace {5mm}X\equiv y(r)$$ have a unique solution mod $[q,r]$ provided $(q,r)|x-y$", but I can't make it work in the above case either.