TITLE: An equality involving roots of unity which holds most of the times, but not always
QUESTION [16 upvotes]: 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?

REPLY [30 votes]: 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$).