<s>[INST] Prove that $x^2 \equiv y^2 \pmod p$ if and only if $x \equiv y \pmod p$ or $x \equiv -y \pmod p$. Hint: $x^2-y^2 = (x+y)(x-y)$. This is the exercise verbatim:
An integer n is a square modulo p if there exists another integer x
such that $n \equiv x^2 \pmod p$. Prove that $x^2 \equiv y^2 \pmod p$ if and only if $x \equiv y \pmod p$ or $x \equiv  -y \pmod p$.
Hint: $x^2-y^2 = (x+y)(x-y)$.
This is my attempt to solve it:
If $x \equiv y \pmod p$ then $\displaystyle \frac{x-y}{p} = q_1 \Rightarrow (x-y)=pq_1$.
If $x \equiv -y$ then $\displaystyle \frac {x+y}{p}=q_2 \Rightarrow (x +y)=pq_2$.
Then $x^2-y^2 = (x+y)(x-y)=(q_1p)\cdot(q_2p)=q_1q_2p^2$
If $p$ is to divide $ x^2-y^2 $ evenly, then it must also divide $q_1q_2p^2$, therefore $\displaystyle \frac {x^2-y^2}{p}=q_1q_2p$.
To satisfy the condition of divisibility by $p$, $q_1q_2p$ must be an integer. Since the assertion to be proven is "Prove that $x^2 \equiv y^2 \pmod p$ if and only if $x \equiv y \pmod p$ or $x \equiv  -y \pmod p$.", we must show that the premise is true if either $q_1$ or $q_2$ is an integer for sure.
Is this line of reasoning correct up until this point?
How to guarantee that $q_1q_2p$ is an integer?  
 [/INST] if $x^2 \equiv y^2 \pmod p$ then $p \mid x^2 - y^2$ and so  $p \mid (x-y)(x+y)$ And so by euclids lemma , since $p$ is prime then we have $p \mid (x-y)$ or $p \mid (x+y)$ and so $x \equiv y \pmod p$ or $x \equiv -y \pmod p$
On the other hand if $x \equiv y \pmod p$ or $x \equiv -y \pmod p$ then assume that $x \equiv y \pmod p$ which implies that $p \mid x-y$ and so there exists an integer $k$ such that $pk = x-y$ Now you multiply both sides by $(x+y)$ to get $pk(x+y) = x^2 - y^2$ and let $t = k(x+y)$ and so you have that $pt = x^2-y^2$ and so $p \mid x^2 -y^2$ and so you get the result that $x^2 \equiv y^2 \pmod p$
Same thing you can do if you assume that $x \equiv -y \pmod p$ but you will just multiply by $(x-y)$ instead.
</s>