Assume n is an integer. If the square root of $n$ is rational, prove that $n$ is a perfect square.
To prove the above statement, I used a trick rather than the standard way of using the unique factorization theorem over the field of integers. My professor claims that my proof is wrong but I don't know where it went wrong. The proof is as follows:
If $\sqrt{n}$ is rational, then there exists integers $p,q$ with $\gcd(p,q) = 1$ such that $\sqrt{n} = \dfrac{p}{q}$.Therefore by multiplying both sides by $\sqrt{n}$ I obtain $n = \dfrac{p}{q}\sqrt{n}$ or $\sqrt{n} =\dfrac{q *n}{p}$. Since $\sqrt{n} = \dfrac{p}{q}$ and $ \sqrt{n} = \dfrac{q *n}{p}$, we can deduce that $ \dfrac{p}{q} = \dfrac{q *n}{p}$. I believe the proof is fine up to this part.
Now I claim the following: Since $\gcd(p,q) = 1$, $\frac{p}{q}$ is in lowest terms. Since $p,q,n$ are all positive integers, there must exist some positive integer $r$ such that $p*r = q*n$ and $q *r = p$. (I believe this is the fishy part. Perhaps this can't be justified straight from definition of equivalence classes?).
As such, we know $q*r = p$ or $ r = \dfrac{p}{q} = \sqrt{n} \implies r^2 = n$. Since $r$ is an integer, $n$ must be a perfect square.
Where did my proof go wrong?