Hypothesis: Let $G$, $H$, $G'$, and $H'$ be cyclic groups of orders $m$, $n$, $m'$, and $n'$ respectively.
Goal: Show that if $G * H$ is isomorphic to $G' * H'$ then $m = m'$ and $n=n'$ or else $m = n'$ and $n = m'$. Here $G * H$ is meant to denote the free product of groups.
Attempt:
Suppose it's not the case that $m = n'$ and $n = m'$. I will show that $n = n'$ and $m' = m'$ so that the desired result follows.
Let $x \in G * H$.
Then $x = g_1 h_1 \cdot \ldots \cdot g_k h_k$ uniquely s.t. $1\ne g_i \in G$, $1 \ne h_i \in H$ and $g_1$ and $h_k$ might be the empty element. Furthermore -- since all our groups are cyclic -- we can let $\left\langle g \right\rangle = G$ and $h = \left\langle H \right\rangle$ and observe that
$$ x = g^{\alpha_1} h^{\beta_1} \cdot \ldots g^{\alpha_k} h^{\beta_k} $$
uniquely since each $g_i = g^{\alpha_i}$ for some $\alpha_i \in \{1, \ldots , m-1\}$ and each $h_i = h^{\beta_i}$ for some $\beta_i \in \{1, \ldots , n-1\}$.
Under the isomorphism $f$ between $G * H$ and $G' * H'$ there exists an analogous element $f(x) = x' \in G' * H'$. We can use the isomorphism properties of $f$ to conclude that $x'$ has the following expression in $G' * H'$
$$ f(x) = f \left(g^{\alpha_1} h^{\beta_1} \cdot \ldots g^{\alpha_k} h^{\beta_k}\right) = f(g)^{\alpha_1} f(h)^{\beta_1} \cdot \ldots f(g)^{\alpha_k} f(h)^{\beta_k} = x' $$
From (3), we know that by the orders of the groups given in the hypothesis that each $\alpha_i$ and $\beta_i$ must satisfy
$$ 0 < \alpha_i < m \text{ and } 0 < \beta_i < n $$
respectively.
Now it must be that $f(g)$ and $f(h)$ map to generators of $G'$ and $H'$ (not necessarily in this order). This is because $f$ being an isomorphism also means $f$ is -- in particular -- a surjection. Yet it is clear from the expression of $f(x)$ in (4) that if $f(g)$ and $f(h)$ didn't map to generators of $G'$ and $H'$, it would be impossible for $\{f(x) : x \in G * H\}$ to equal $G' * H'$.
Then
$$ m = |G| = \underbrace{|\{ g^k : k \in \mathbb{N} \}|}_{\text{since $g$ generates $G$}} = \underbrace{|\{f(g)^k : k \in \mathbb{N}\}|}_{\text{since $f$ is bijective}} \underbrace{= |X| \text{ s.t. } X = G' \text{ or } X = H'}_{\text{since $f(g)$ is a generator of either $G'$ or $H'$}} $$
and
$$ n = |H| = \underbrace{|\{ h^k : k \in \mathbb{N} \}|}_{\text{since $h$ generates $H$}} = \underbrace{|\{f(h)^k : k \in \mathbb{N}\}|}_{\text{since $f$ is bijective}} \underbrace{= |Y| \text{ s.t. } Y = G' \text{ or } X = H'}_{\text{since $f(h)$ is a generator of either $G'$ or $H'$}} $$
If $X = H'$ and $Y = G'$, then $m = n'$ and $n = m'$ -- contradicting (1).
Then it must be that $X = G'$ and $Y = H'$ so that $m = m'$ and $n = n'$. This completes the proof.
Question: Is my proof valid?