To show that group G is abelian if $(ab)^3 = a^3 b^3$ and the order of $G$ is not divisible by 3 
Let $G$ be a finite group whose order is not divisible by $3$.
  suppose $(ab)^3 = a^3 b^3$ for all $a,b \in G$. Prove that $G$ must be abelian.

Let$ $G be a finite group of order $n$. As $n$ is not divisible by $3$ ,$3$ does not divide $n$ thus $n$ should be relatively prime to $n$. that is gcd of an $n$ should be $1$.
  $n =  1 ,2 ,4 ,5 ,7 ,8 ,10 ,11, 13 ,14 ,17,...$
 further I know that all groups upto order $5$ are abelian and every group of prime order is cyclic. when it remains to prove the numbers which are greater than $5$ and not prime are abelian.
Am I going the right way?
 please suggest me the proper way to prove this.
 A: Since this has appeared on the top, here is a shorter proof of the result. It starts the same, as it has to: $(ab)^3=a^3b^3$ implies $baba=aabb$. But now multiply by $ba$ on the left:
$$bababa=baaabb.$$
But the left-hand side is $b^3a^3$, and we cancel off the first $b$ to achieve $b^2a^3=a^3b^2$, i.e., for all $a,b$, $a^3$ commutes with $b^2$.
Now we use the fact (mentioned elsewhere) that since $3\nmid |G|$, $x\mapsto x^3$ is a bijection, and so $b^2$ in fact commutes with $a$, for all $a,b\in G$. Consequently, $b^2$ commutes with $a^2$ as well. But now we go back to our first statement $baba=aabb$: we obtain
$$ baba=aabb=bbaa.$$
Removing the front $b$ and the back $a$ yields $ab=ba$, as needed.
A: I have followed the similar method as previous answer with a few changes (without defining the $f$, thought it would be easier:) )
As $(ab)^3=a^3b^3$ for all $a,b\in G$
we have \begin{align*} ababab&=aaabbb\\
\Rightarrow baba&=aabb\\
\Rightarrow (ba)^2&=a^2b^2 \end{align*}
Consider,
\begin{align*}(ab)^4&=((ab)^2)^2\\
&=(b^2a^2)^2\\
&=a^4b^4
\\
&=aaaabbbb\end{align*}
Also
\begin{align*}
(ab)^4&=abababab\\
&=a(ba)^3b
\end{align*}
Therefore, we get
\begin{align}aaaabbbb&=a(ba)^3b\\
\Rightarrow (ba)^3&=(ab)^3\\
\Rightarrow (ab)^{-3}(ba)^3&=e
\end{align}
Where $e$ is identity in $G$
$$\Rightarrow [(ab)^{-1}(ba)]^3=e$$
Now for $x=(ab)^{-1}(ba)$ ,$|x|$ divides $3$ by which $|x|$ can be $3$ or $1$.
Now $|x|$ can not be $3$ (as by Lagrange's theorem if $|x|$=3 then $3$ divides $|G|$ which is not true).
Thus,
\begin{align*}
|x|&=1\\
\Rightarrow x&=e\\
\Rightarrow (ab)^{-1}(ba)&=e
\end{align*}
Multiplying by $ab$ from left,
$$\Rightarrow ba=ab$$ for all $a,b\in G$.
Thus, $G$ is abelian.
A: First note that given condition says that $ f: G \to G$ defined as $x \to x^3$ is an injective homomorphism of $G$.
Further Note that
$$
\forall a,b \in G: \quad ababab = (ab)^{3} = a^{3} b^{3} = aaabbb.
$$
Hence,
$$
\forall a,b \in G: \quad baba = aabb, \quad \text{or equivalently}, \quad (ba)^{2} = a^{2} b^{2}.
$$
Using this fact, we obtain
\begin{align}
\forall a,b \in G: \quad (ab)^{4} &= [(ab)^{2}]^{2} \\
                                  &= [b^{2} a^{2}]^{2} \\
                                  &= (a^{2})^{2} (b^{2})^{2} \\
                                  &= a^{4} b^{4} \\
                                  &= aaaabbbb.
\end{align}


*

*On the other hand,
\begin{align}
\forall a,b \in G: \quad (ab)^{4} &= abababab \\
                                  &= a (ba)^{3} b \\
                                  &= a b^{3} a^{3} b \\
                                  &= abbbaaab.
\end{align}

*Hence, for all $ a,b \in G $, we have $ aaaabbbb = abbbaaab $, which yields
$$
f(ab) = a^{3} b^{3} = b^{3} a^{3} = f(ba).
$$
As $ f $ is injective, we conclude that $ ab = ba $ for all $ a,b \in G $.Hence $G$ is an abelian group

Added: I think it's worth mentioning that  there exist nonabelian group $G$ for which $x \to x^3$ is a group homomorphism.Smallest such example is Heisenberg group of order $27$ which can be thought of as all $3 \times 3$ upper diagonal matrices with $1's$ on the diagonal and other entries in the field of order $3$.As $G$ is  of exponent 3 ( i.e. $x^3=1$ for all $x \in G$) hence $f$ is a homomorphism and $G$ is clearly  non abelian because for example following two matrices don't commute:
$$\left(\begin{array}{ccc}
1 & 1 & 0\\
0 & 1 & 2\\
0 & 0 & 1
\end{array}\right),$$ $$\left(\begin{array}{ccc}
1 & 1 & 0\\
0 & 1 & 1\\
0 & 0 & 1
\end{array}\right)$$
In particular this also shows that the condition that $3$ does not divide order($G$) is necessary.
A: I am reading "Topics in Algebra 2nd Edition" by I. N. Herstein.
This problem is the same problem as Problem 24 on p.48 in Herstein's book.
I solved this problem as follows:

$G\ni x\mapsto x^3\in G$ is a homomorphism since $(ab)^3=a^3b^3$ for all $a,b\in G$ by the assumption of this problem.
Assume that there exists $a\in G$ such that $a\ne e$ and $a^3=e$.
If $a^2=e$, then $a^3=a^2\cdot a=e\cdot a=a\ne e$.
But $a^3=e$ by our assumption.
So, $a^2\ne e$ must hold.
So, $o(a)=3$.
By a famous theorem, $o(a)\mid\#G$.
So, $3\mid\#G$.
But $3\not\mid\#G$ by the assumption of this problem.
So, this is a contradiction.
So, there does not exist $a\in G$ such that $a\ne e$ and $a^3=e$.
So, if $a^3=e$, then $a=e$ must hold.
So, the kernel of the homomorphism $G\ni x\mapsto x^3\in G$ is $\{e\}$.
So, the homomorphism $G\ni x\mapsto x^3\in G$ is injective.
Since $G$ is finite by the assumption of this problem, the homomorphism $G\ni x\mapsto x^3\in G$ is bijective.
Let $a,b\in G$.
$b(abab)a=(ba)^3=b^3a^3=b(bbaa)a$ by the assumption of this problem.
So, by the left cancellation law and the right cancellation law, we get $abab=bbaa$.
So, $(ab)^2=b^2a^2$ for any $a,b\in G$.
$(ab)^4=((ab)^2)^2=(b^2a^2)^2$.
Let $A:=b^2$ and $B:=a^2$.
Then, $(b^2a^2)^2=(AB)^2=B^2A^2=a^4b^4$.
So, $(ab)^4=a^4b^4$ for any $a,b\in G$.
$(ab)^4=a^4b^4=a(a^3b^3)b$.
$(ab)^4=a(bababa)b=a(ba)^3b$.
So, $a(a^3b^3)b=a(ba)^3b$.
By the left cancellation law and the right cancellation law, we get $a^3b^3=(ba)^3$ for any $a,b\in G$.
$(ba)^3=b^3a^3$ by the assumption of this problem.
So, $a^3b^3=b^3a^3$ for any $a,b\in G$.
Let $a,b\in G$.
Then, there exist $a^{'},b^{'}\in G$ such that $(a^{'})^3=a,(b^{'})^3=b$ since
$G\ni x\mapsto x^3\in G$ is surjective.
$ab=(a^{'})^3(b^{'})^3=(b^{'})^3(a^{'})^3=ba$.

