I have a specific question on the proof that any two finite cyclic groups of order $n$ are isomorphic. Let's say that $G = \langle x \rangle$ and $H = \langle y \rangle$. The isomorphism that appears "natural" is $f: G \to H$ defined by $g(x^i) = y^i$. In order to check that this is a homomorphism, I have to consider the possibility that the exponents of my two elements are greater than $n$, so I can't just define this map for $0 \leq i < n$. It seems to me that I need to check that it is well-defined for any integer $i$.
That is, I want to check that for any $i,j \in \mathbb{Z}$, if $x^i = x^j$, then $y^i = y^j$. I am stuck on how to do this, however. Here is one attempt. I think I need to at some point use the division algorithm.
Suppose $x^i = x^j$ for $i,j \in \mathbb{Z}$. Then $x^{i-j} = e_G$. By the division algorithm, there exist unique $q,r \in \mathbb{Z}$ with $0 \leq r < n$ such that $$ i - j = qn + r. $$ We need to show that $y^{i-j} = e_H$, hence $y^i = y^j$. We have $$ y^{i-j} = y^{qn + r} = (y^n)^q y^r = ey^r = y^r. $$
At this point, I am not sure how to proceed. Ideally, I'd be able to conclude that $r = 0$, but I could do that only if $y^r = e_H$, which would assume the conclusion.
I'd appreciate any help with this one step of the proof. I'm fine with the remainder of the proof that these groups are isomorphic.