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

On a practice exam, our teacher provides us with this question and this answer.

Let $p$ be a prime number. Use contradiction to prove that $\sqrt{p}$ is irrational.

ANSWER: BWOC assume $\sqrt{p}$ is rational. Then there exist $a, b \in \mathbb{Z}$ with $b\neq 0$ such ￼￼that $\sqrt{p} = \frac{a}{b}$. ￼￼Without loss of generality, we may assume $\text{gcd}(a,b) = 1$. Then $p = \frac{a^2}{b^2}$. Thus $p | a^2$ which implies $p | a$, i.e., $\exists k \in \mathbb{Z}$ such that $p k = a$. We now have $p b^2 = (\pi k)^2 = p(p k^2)$, so $p b^2 = a^2$. ￼Since $p \neq 0$, $b^2 = p k^2$, which means $p|b$. Thus $p$ is a common factor of $a$ and $b$. This is a contradiction as $a$ and $b$ are relatively prime.

My question is, how do you know to assume that the $\text{gcd} (a,b)=1$? It seems really random and I don't know why the proof jumps there.

-
It means you only want to consider fractions in lowest terms (e.g. worrying only about $1/2$ and not about $2/4$, $3/6$, etc.) –  Guess who it is. May 14 '12 at 16:29
My mistake. By the original title, I assumed the original poster meant "$\sqrt{\pi}$ is irrational. I didn't notice "let $p$ be a prime number". I will edit this now back to $p$. Thanks for point it out. –  Rick May 14 '12 at 16:52
Sorry to post here but i cant comment for some reason. Can somebody explain me why if p/a^2 then p|a ? im missing sth and i dont seem to get it. –  Plom Jun 30 '13 at 21:23
Just leaving this here, because it may be useful... I rarely see people proving this using the fact that if a root of a monic polynomial is rational, than it is an integer and it divides the coefficient free of variables (and it is quite easy to prove this). So, if there was a root of $x^2 - p$, it would have to be $1,-1,p,-p$. It is easily verified that none of them solves it. –  Aloizio Macedo Jun 30 '13 at 23:00

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.
Why did you edit it to change all occurences of $p$ to $\pi$? (You missed the first occurence, where he states $p$ is prime, fwiw.) –  Thomas Andrews May 14 '12 at 16:51