Let $m$ and $n$ be distinct odd positive integers. The equality
$$
 \prod\_{k=0}^{mn-1} \left( e^{\frac{2\pi i k}{m}}
 + e^{\frac{2\pi i k}{n}} \right)
 \ = \ 2^{\gcd(m,n)}
$$
holds for all pairs of such $m$ and $n$ less than $50$ except for
$(3,21)$, $(3,39)$, $(15,33)$ and $(21,39)$, where the left-hand side
takes the value $512 = 2^9$.


**Question:** For which values of $m$ and $n$ does the equation
*not* hold, and which values takes the left-hand side in these cases?



An equality involving roots of unity which holds most of the times, but not always
It always equals $2^{\gcd(m-n,mn)}$. Proof:
denote $x=e^{2\pi i/mn}$. Denote by $A$ the set of residues $k$ modulo $mn$ for which $mn$ divides $k(m-n)$, $|A|=\gcd(m-n,mn)$, $B$ is the set of other residues. We have
$$
\prod\_k (x^{km}+x^{kn})=\prod\_{k\in A} 2x^{km}\cdot \prod\_{k\in B} \frac{x^{2km}-x^{2kn}}{x^{km}-x^{kn}}.
$$
The second product equals 1, since the multiples in the numerator and denominator are the same. The first product equals $2^{|A|}$, since $k$ and $-k$ belong to $A$ simultaneously, and we may couple multiples corresponding to them (with exception $k=0$).


