It is a well known fact, I wonder whether you know about the legender symbole, actually, if an odd prime number

divide

then

is a quadratic residue modulo

which implies by Gauss's Lemma, that

. If you don't know about the legendre symbole, you can prove that fact using only Fermat's Theorem. In fact, if

is an odd prime and

then
^{\frac{p-1}{2}} \equiv x^{p-1}\pmod{p})
this implies after Fermat liltle theorem that
^{\frac{p-1}{2}}=1)
or again