If a and b are relatively prime and ab is a square, then a and b are squares.

Its clear you understand what's going on, but it might help you communicate it more precisely if you use symbols. For example if $a$ has prime factorization $$a = p_1^{l_1} \cdot p_2^{l_2} \cdot \ldots \cdot p_n^{l_n}$$ and $b$ has prime factorization $$b = q_1^{k_1} \cdot q_2^{k_2} \cdot \ldots \cdot q_m^{k_m}$$ then $ab$ has prime factorization $$ab = p_1^{l_1} \cdot p_2^{l_2} \cdot \ldots \cdot p_n^{l_n} \cdot q_1^{k_1} \cdot q_2^{k_2} \cdot \ldots \cdot q_m^{k_m}.$$ There can be no $p_i = q_j$ because $a$ and $b$ are coprime.

Because $ab$ is square, all of the $l_i$ and $k_i$ are even, completing the proof.


Yes, it suffices to examine the parity of exponents of primes. Alternatively, and more generally, we can use gcds to explicitly show $\rm\,a,b\,$ are squares. Writing $\,\rm(m,n,\ldots)\,$ for $\rm\, \gcd(m,n,\ldots)\,$ we have

Theorem $\rm\ \ \color{#C00}{c^2 = ab}\, \Rightarrow\ a = (a,c)^2,\ b = (b,c)^2\: $ if $\rm\ \color{#0A0}{(a,b,c)} = 1\ $ and $\rm\:a,b,c\in \mathbb N$

Proof $\rm\ \ \ \ (a,c)^2 = (a^2,\color{#C00}{c^2},ac)\, =\, (a^2,\color{#C00}{ab},ac)\,=\, a\,\color{#0A0}{(a,b,c)} = a.\, $ Similarly $\rm \,(b,c)^2 = b.$

Yours is the special case $\rm\:(a,b) = 1\ (\Rightarrow\ (a,b,c) = 1)$. The above proof uses only universal gcd laws (associative, commutative, distributive), so it generalizes to any gcd domain/monoid (where, generally, prime factorizations need not exist, but gcds do exist).