If $a, b$ are relatively prime proof and $ab$ is a perfect square, so are $a$, $b$ 
Prove that if $a$ and $b$ are relatively prime integers and $ab$ is a perfect square so are $a$ and $b$. Show by counterexample that the relatively prime condition is necessary.

I dont know how to start this proof. Also the second "counterexample" part is messing me up. Thanks for any help!
 A: Counterexample (hint): take $a=b$ (hint: not any $a$ will do)
Proof (hint): write $ab=c^2$ and consider the decomposition of $c$ into prime factors; each of these occurs either in $a$ or in $b$ but not in both.
A: First, you must restrict to $\,a,b\in \Bbb N\,$ else it is false, e.g. $\, (-1)(-4) = 2^2$ but $\,-4\,$ is not a square.
Theorem $\ a,b\,$ coprime, $\, ab=n^2\Rightarrow\, a,b\,$ are squares, if $\,a,b,n\in \Bbb N.$
Proof $\ $ By induction on $\,n.\,$ Clear if $\,n=1.\,$  Else $\,n > 1,\,$ so some prime $\,p\mid n\,$ so $\,p^2\mid n^2\!= ab,\,$ $\rm\color{#c00}{thus}$ $\,p^2\mid a\,$ or $\,p^2\mid b,\,$ by $\,a,b\,$ coprime. Wlog $\,p^2\mid b,\,$ thus $\,ab=n^2\Rightarrow\ a(b/p^2) = (n/p)^2$ by canceling $\,p^2.\,$ Since $\,n/p < n,\,$ by induction there are $\,c,d\in\Bbb N$ such that $\, a = c^2,\ b/p^2 = d^2,\,$ so $\,b = (pd)^2.\  $ QED
Remark $\ $ The $\rm\color{#c00}{key\ property}$ used is that $\,p^2\mid ab\,\Rightarrow\,p^2\mid a\,$ or $\,p^2\mid b,\:$ if $\,a,b\,$ are coprime. This is an immediate consequence of the Fundamental Theorem of Arithmetic (existence and uniqueness of prime factorizations), or  equivalent well-known properties, e.g. one can iterate Euclid's Lemma $\ p\mid ab\,\Rightarrow\, p\mid a\,$ or $\,p\mid b.\,$ The same holds true for $\,k$'th powers of primes, so the proof generalizes from squares to $\,k$'th powers and, further, from $\,\Bbb Z\,$ to any UFD (e.g. $\,F[x],\,$ a polynomial ring over a field). In the general case one must allow for unit factors, i.e. the result is that $\,a = uc^2,\ b = u^{-1} d^2$ for some $\,c,d\,$ and some unit (invertible) $\,u.\,$ We eliminated $\, u = \pm1 \in \Bbb Z\,$ by requiring $\,a,b > 0.$
A: Here is some help on the proof, I see there is already help for the counterexample.
If $a$ and $b$ are relatively prime then consider the prime factorization of each
$$a = p_1^{a_1} \cdots p_k^{a_k}$$
$$b = q_1^{b_1} \cdots q_m^{b_m}$$
since they are relatively prime they can share no prime factors. That is $p_i \ne q_j$ for any $i$ and $j$. Now
$$ab = p_1^{a_1} \cdots p_k^{a_k}q_1^{b_1} \cdots q_m^{b_m}$$
is a perfect square. What does this say about the exponents? (Hint: Think about parity)
A: A perfect square has only prime factors with an even exponent, like $86436=2^2\cdot3^2\cdot7^4$.
If $a$ and $b$ have no common prime factor, then all their own exponents must be even. Like $9604=2^2\cdot7^4$ and $9=3^2$.
But when $a$ and $b$ have common prime factors with an odd exponent, the product will have an even exponent as well. Like $1372=2^2\cdot7^3$ and $63=3^2\cdot7$.
Beware that you can also have non-relatively-primes $a$ and $b$ giving a perfect square and being perfect squares themselves, like $196=2^2\cdot7^2$ and $441=3^2\cdot7^2$.
A: Consider $a=p^{\alpha_1}_1p^{\alpha_2}_2\cdots~p^{\alpha_r}_r$ and $b=q^{\beta_1}_1q^{\beta_2}_2\cdots~q^{\beta_s}_s$. Since $gcd(a,b)=1$ we have $\{p_1,p_2,\cdots,p_r\} \cap \{q_1,q_2,\cdots,q_s\} = \phi$. Now $ab=p^{\alpha_1}_1p^{\alpha_2}_2\cdots~p^{\alpha_r}_r\times q^{\beta_1}_1q^{\beta_2}_2\cdots~q^{\beta_s}_s$ and $ab$ is a perfect square hence all exponents of $p_i's$ and $q_j's$ are even for $1\leq i\leq r$, $1\leq j\leq s$. Hence $a$ and $b$ are also square since exponent are even.
