Original problem
A function $g$ from a set $X$ to itself satisfies $g^m=g^n$ for positive $m$ and $n$ with $m>n$. Here $g^n$ stands for $g\circ g\circ \dots g$(n times). Show that $g$ is one-one if and only if $g$ is onto.
My work
Let $h=g^m$ and $f=g^n$.
Therefore $h=f$ and also $h=h=f=f\circ g^{m-n}$
Therefore we have $g^{m-n}(x)=x$
Is my work correct? If yes then how to proceed further.