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?  
 A: Definition: $a\equiv b\pmod{\! n}$ iff $n\mid a-b$. Use it repeatedly.  
$$x^2\equiv y^2\pmod{\! p}\iff p\mid x^2-y^2=(x+y)(x-y)$$    
Read about Euclid's Lemma, get:   
$$\begin{align}\color{\#0bd}\iff ((p\mid x+y)&\ \text{ or }\ (p\mid x-y))\\\iff ((x\equiv -y\pmod{\! p})&\ \text{ or }\ (x\equiv y\pmod{\! p}))\end{align}$$   
Euclid's lemma claims $\color{LightGreen}{p\mid ab}\,\color{\#0bd}\Rightarrow\, \color{#4b3}{((p\mid a)\, \text{ or }\, (p\mid b))}$, but I wrote '$\color{\#0bd}\iff$' there because: $$\color{#4b3}{((p\mid a)\text{ or }(p\mid b))}\iff ((a=pa_1)\text{ or }(b=pb_1))$$   
for some $a_1,b_1\in\Bbb Z$ by the exact definition of divisibility, and $$\iff ((ab=p(a_1b))\ \text{ or }\ (ab=p(b_1a)))$$   
$$\implies  ((p\mid ab)\text{ or }(p\mid ab))\iff \color{LightGreen}{p\mid ab}$$
A: You can use the theorem : p( a prime) divides the product $ab$ if and only if  p divides $a$ or $p$ divides $b$. Now $x^{2} \equiv y^{2}$ mod $p$ if and only if $p$ divides $x^{2}-y^{2}=(x-y)(x+y)$, if and only if $p$ divides $x+y$ or $p$ divides $x-y$ if and only if $x \equiv y$ mod $p$ o $x \equiv -y$ mod p.
A: Well, use your hint:
$$x^2 - y^2 \equiv 0 \pmod p$$
$$(x+y)(x-y) \equiv 0 \pmod p$$
Clearly, ths is satisfied if $x=y$ or $x=-y$. Because $\mathbb{Z}_p$ has no zero divisors, these are the only solutions.
A: 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.
