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$?