I read the following proof in a book while I seeing the proof that is irrational if $n$ is not a perfect square number. The proof is as follows-
Let, if possible, there exists rational number $\frac pq$=$\sqrt n$ ($p $ and $q$ are co-prime). Squaring both sides $p^2=n*q^2$.
From above we get $n$ is a factor of $p^2$. Now, it is written that we can deduce $n$ is a factor of $p$.
Similarly it is also proved that n is a factor of q. From that we get that $p$ and $q$ both have some common factor $n$ which contradicts the hypothesis that $\frac pq$ is co-prime. So our assumption was wrong.
Now, my question is, how can it be said that if $n$ is a factor of $p^2$ it will also be a factor of $p$? Take an example- $72$ is a factor of $12^2=144$ but it is not a factor of $12$.
Where am I wrong? Please explain.