use contradiction to prove that the square root of $p$ is irrational

Solution 1:

You can make this assumption, because you lose no generality. Indeed, suppose $\text{gcd} (a,b) = d \neq 1$. Then we can write $a = d \cdot a'$ and $b = d \cdot b'$, for some relatively prime integers $a'$ and $b'$. But then $$ \sqrt{p} = \frac{a}{b} = \frac{d a'}{d b'} = \frac{a'}{b'}, $$ so you are back in the situation that you wrote above, i.e. that $\sqrt{p}$ is a ratio of two relatively prime integers.