When does $(ab)^n = a^n b^n$ imply a group is abelian? Suppose the identity $(ab)^n = a^n b^n$ holds in a group for some $n\in\mathbb{Z}$. For which $n$ does this necessarily imply the group is abelian? For example, when $n=-1$ or $n=2$, the group must be abelian. Are there any other such $n$, or can we construct a non-abelian group with this property for all $n\neq -1, 2$?
 A: Let $n$ be such that $n \neq \pm 1$, $n \neq 2$ (the case $n=1$ is trivial, $-1$ and $2$ imply that the group is abelian).


*

*If $n$ is a power of $2$ (greater than $2$ in absolute value), then let $G = \mathbb{H}$be the quaternion group. It's nonabelian and has exponent $4$ (which divides $n$), so for all $a,b$, $(ab)^n = e = ee = a^n b^n$.

*If $n$ is not a power of $2$, then let $p > 2$ be a prime number dividing $n$, say $n = pk$. Let $G$ be the group described in this question: it's a nonabelian group that has exponent $p$. Then for all $a,b \in G$, $(ab)^n = ((ab)^p)^k = e = (a^p)^k (b^p)^k = a^n b^n$.

*If $n=-2$, let $G$ be the nonabelian group of exponent $3$ we used before. Then $\forall a \in G, a^{-2} = a$, from which the identity follows. (Thanks to Mikko Korhonen for pointing out the mistake in the first version of this answer).
A: For any non-abelian group $\;G\;$ of exponent $\;n\;$ we have that $\;1=(ab)^n=a^nb^n\;$ , so for any natural $\;n\;$ for which there exists at least one non abelian group with that exponent we get a counterexample.
A: Note that if $G$ is a group with exponent dividing $n-1$ or $n$, then $(xy)^n = x^n y^n$ for all $x, y \in G$.
Suppose that $n \neq -1, 2$. By above it would be enough to prove that in this case we can find a nonabelian group with exponent dividing $n-1$ or $n$. By the assumption either $n-1$ or $n$ has an odd prime divisor $p$, so we could use for example the Heisenberg group of order $p^3$, which has exponent $p$.
