I was doing the first exercises from the book Exercises in Basic Ring Theory by G. Călugărescu and P. Hamburg and I found one whose solution isn't quite clear to me.
Ex. 1.4 If $a$, $b$ are elements in a ring $R$ and $n$, $m$ $\in \mathbb{N}^*$, $(n;m)=\text{gcd}(n,m)=1$ are such that $a^n=b^n$ and $a^m=b^m$ then $a=b$.
Solution: If $(n;m)=1$ there are integers $s,t \in \mathbb{Z}$ such that $sn+tm=1$. But then $a=a^1=a^{sn+tn}=(a^n)^s·(a^m)^t=(b^n)^s·(b^m)^t=b^{sn+tm}=b^1=b$.
Now, in the book they don't consider rings to be integral domains; indeed they don't even consider rings to be commutative. So, since $s$ or $t$ might be negative, how can be justified the step $a^{sn+tn}=(a^n)^s·(a^m)^t$?
It is true if the ring does not have divisor of zero.
Suppose that $m<n$, write $n=pm+r$, you have $a^n=a^{pm+r}=b^{pm+r}=b^{pm}b^r=a^{pm}b^r$. You deduce that $a^{pm}a^r=a^{pm}b^r$ and $a^{pm}(a^r-b^r)$ and $a^r=b^r$.
Thus the assertion is true for $(m,r)$ you can repeat this process until the rest is 1.