The contradiction method used to prove that the square root of a prime is irrational

The contradiction method given in certain books to prove that sqare root of a prime is irrational also shows that sqare root of $4$ is irrational, so how is it acceptable? e.g. Suppose $\sqrt{4}$ is rational,
$$\begin{align} \sqrt{4} &=p/q \qquad\text{where pand q are coprimes} \\ 4 &=p^2/q^2\\ 4q^2&=p^2 \tag{1} \\ 4&\mid p^2\\ 4&\mid p\\ \text {let }p&=4m \qquad\text{for some natural no. m} \\ p^2&=16m^2\\ 4q^2&=16m^2 \qquad\text{(from (1) )}\\ q^2&=4m^2\\ 4& \mid q^2\\ 4&\mid q \end{align} $$ but this contradicts our assumption that $p$ and $q$ are coprime since they have a common factor $p$. Hence $\sqrt{4}$ is not rational. But we know that it is a rational. Why?


Solution 1:

If $4q^2 = p^2$, $4$ is a factor of $p^2$, but it does not follow that $4$ is a factor of $p$ only that $2$ is a factor of $p$. For example, $4$ is a factor of $36$, but $4$ is not a factor of $6$ (but $2$ is).

In general, if $a$ is prime and $a$ is a factor of $pq$ then $a$ must be a factor of $p$ or a factor of $q$ (or both); in particular, if $a$ is a factor of $p^2$, then $a$ must be a factor of $p$. It then follows that if $m$ is a product of distinct primes, then if $m$ is a factor of $p^2$, $m$ must be a factor of $p$. So the method used to show that the square root of a prime number is irrational extends to numbers which are the product of distinct primes, but no further.

Solution 2:

The step from $4\mid p^2$ to $4\mid p$ is wrong. For example, take $p=6$. Then $4\mid 6^2$ but it is not true that $4\mid 6$.

In general, $q\mid p^2$ implies $q\mid p$ only for squarefree $q$. A number $q$ is "squarefree" if it is not divisible by any square larger than 1.