For which prime numbers $p$ is $2$ a quadratic residue modulo $p$.
I know that $2$ is a quadratic residue iff $$2^{\frac{p-1}{2}} =1 \; \bmod \;(p) $$ so $$2^{p-1} =1 \; \mod \; (p). $$ But I don't know what to do.
For which prime numbers $p$ is $2$ a quadratic residue modulo $p$.
I know that $2$ is a quadratic residue iff $$2^{\frac{p-1}{2}} =1 \; \bmod \;(p) $$ so $$2^{p-1} =1 \; \mod \; (p). $$ But I don't know what to do.
Let $s = \frac{p-1}{2}$, and consider the $s$ equations
$$\begin{align} 1&= (-1)(-1) \\ 2&=2(-1)^2 \\ 3&= (-3)(-1)^3 \\ 4&= 4 (-1)^4 \\ & \quad\quad \ldots\\ s&= (\pm s)(-1)^s \end{align}$$
Where the sign is always chosen to have the correct resulting sign.
Now multiply the $s$ equations together. Clearly on the left we have $s!$. On the right, we have a $2,4,6,\dots$ and some negative odd numbers. But note that $2(s) \equiv -1 \mod p$, $2(s-1) \equiv - 3 \mod p$, and so on, so that the negative numbers are the rest of the even numbers mod $p$, but disguised. So the right side contains $s! (2^s)$ (where we intuit this to mean that one two goes to each of the terms of the factorial, to represent the even numbers $\mod p$).
We only have consideration of $(-1)^{1 + 2 + \ldots + s} = (-1)^{s(s+1)/2}$ left.
Putting this all together, we get that $2^s s! \equiv s! (-1)^{s(s+1)/2} \mod p$, or upon cancelling factorials that $2^s \equiv (-1)^{s(s+1)/2}$. And $s(s+1)/2 = (p^2 - 1)/8$, so we really have $2^{(p-1)/2} \equiv (-1)^{(p^2 - 1)/8}$.
So it depends on $p \pmod 8$. [This is probably the involved manipulation of factorial proof that André alludes to].
The other method is based on roots of unity $$\sqrt{2}e^{2i \pi /8}= 1+i$$ For $p$ odd $$(\sqrt{2}e^{2i \pi /8})^p = \sqrt{2} 2^{(p-1)/2}e^{2i \pi /8} (e^{2i \pi /8})^{p-1}=(1+i)\left(\frac{2}{p}\right)i^{(p-1)/2}$$
$$(1+i)^p \equiv 1^p+i^p \equiv 1+i (-1)^{(p-1)/2}\equiv (1+i) i^{(p-1)/2} (-1)^{(p^2-1)/8} \bmod p $$ Thus $$ \left(\frac{2}{p}\right) \equiv (-1)^{(p^2-1)/8} \bmod p$$
The second supplementary law of quadratic reciprocity says that: $$\biggl(\frac{2}p\biggr)=\bigl(-1\bigr)^{\tfrac{p^2-1}8}$$ Namely, $2$ is a square modulo $p$ if and only if $p\equiv\pm 1\mod 8$.
The argument below is from exercise 5.38 on p.65 of Ireland & Rosen's A Classical Introduction to Modern Number Theory 2nd Ed.
Let $p$ be an odd prime. Derive the quadratic character of $2$ modulo $p$ by verifying the following steps, involving the Jacobi symbol:
$\left(\frac{2}{p}\right)=\left(\frac{8-p}{p}\right)=\left(\frac{p}{p-8}\right)=\left(\frac{8}{p-8}\right)=\left(\frac{2}{p-8}\right)$.
Generalize the argument to show that
$$\left(\frac{a}{p}\right)=\left(\frac{a}{p-4a}\right),\,\,\,a>0,p\not\mid a.$$
We will show directly that $\left(\frac{a}{p}\right)=\left(\frac{a}{p-4a}\right)$. It follows immediately that $\left(\frac{2}{p}\right)=\left(\frac{2}{p-8}\right)$.
We first verify that $\frac{p-1}{2}\frac{p-4a+1}{2}\equiv0\pmod2$. If $p=4k+1$, then $\frac{p-1}{2}\frac{p-4a+1}{2}=2k\cdot\frac{p-4a+1}{2}\equiv0\pmod2$. If $p=4k-1$, then $\frac{p-1}{2}\frac{p-4a+1}{2}\equiv\frac{p-1}{2}\cdot2(k-a)\equiv0\pmod2$.
Now, \begin{align*} \left(\frac{a}{p}\right)&=\left(\frac{4a}{p}\right)\\ &=\left(\frac{4a-p}{p}\right)\\ &=\left(\frac{-1}{p}\right)\left(\frac{p-4a}{p}\right)\\ &=(-1)^{\frac{p-1}{2}}\left(\frac{p}{p-4a}\right)(-1)^{\frac{p-1}{2}\frac{p-4a-1}{2}}\\ &=(-1)^{\frac{p-1}{2}\frac{p-4a+1}{2}}\left(\frac{4a}{p-4a}\right)\\ &=\left(\frac{a}{p-4a}\right). \end{align*} (Notice that we did not need to assume $a>0$ or $p\not\mid a$, and the argument still holds if $p$ is replaced by an arbitrary odd $b$ and $b-4a>0$ so that we can use reciprocity law for Jacobi symbol.)
By induction, we have $\left(\frac{a}{p}\right)=\left(\frac{a}{p-4ma}\right)$ for any positive $m$.
We have the following cases:
If $p=8n+1$, then $\left(\frac{2}{p}\right)=\left(\frac{2}{p-8n}\right)=\left(\frac{2}{1}\right)=1$.
If $p=8n+3$, then $\left(\frac{2}{p}\right)=\left(\frac{2}{p-8n}\right)=\left(\frac{2}{3}\right)=-1$.
If $p=8n+5$, then $\left(\frac{2}{p}\right)=\left(\frac{2}{p-8n}\right)=\left(\frac{2}{5}\right)=-1$.
If $p=8n+7$, then $\left(\frac{2}{p}\right)=\left(\frac{2}{p-8n}\right)=\left(\frac{2}{7}\right)=1$.
So $2$ is a square modulo $p$ iff $p\equiv\pm1\pmod8$, or $\left(\frac{2}{p}\right)=(-1)^{(p^2-1)/8}$.
The argument below is from exercise 5.32 on p.64 of Ireland & Rosen's A Classical Introduction to Modern Number Theory 2nd Ed.
If $p$ is an odd prime show that $(2/p)=\prod_{j=1}^{(p-1)/2}2\cos(2\pi j/p)$. Use this result to give another proof to Proposition 5.1.3.
Note that Proposition 5.1.3 refers to
$2$ is a quadratic residue of primes of the form $8k+1$ and $8k+7$. $2$ is a quadratic nonresidue of primes of the form $8k+3$ and $8k+5$. This information is summarized in the formula $$\left(\frac{2}{p}\right)=(-1)^{(p^2-1)/8}.$$
Let $f(z)=e^{2\pi iz}-e^{-2\pi iz}=2i\sin(2\pi z)$. Proposition 5.3.2 (on p.60) gives \begin{align*} \prod_{l=1}^{(p-1)/2}f\left(\frac{2l}{p}\right)=\left(\frac{2}{p}\right)\prod_{l=1}^{(p-1)/2}f\left(\frac{l}{p}\right). \end{align*} We have \begin{align*} \left(\frac{2}{p}\right)&=\prod_{l=1}^{(p-1)/2}\frac{f\left(\frac{2l}{p}\right)}{f\left(\frac{l}{p}\right)}\\ &=\prod_{l=1}^{(p-1)/2}\frac{\sin(4\pi l/p)}{\sin(2\pi l/p)}\\ &=\prod_{l=1}^{(p-1)/2}\frac{2\sin(2\pi l/p)\cos(2\pi l/p)}{\sin(2\pi l/p)}\\ &=\prod_{j=1}^{(p-1)/2}2\cos(2\pi j/p). \end{align*}
Hence, $\left(\frac{2}{p}\right)=\operatorname{sgn}\left(\prod_{j=1}^{(p-1)/2}2\cos(2\pi j/p)\right)=\operatorname{sgn}\left(\prod_{j=1}^{(p-1)/2}\cos(2\pi j/p)\right)$.
Now, $\cos(2\pi j/p)>0$ iff $0<\frac{2\pi j}{p}<\frac{\pi}{2}$ iff $0<j<\frac{p}{4}$. Similarly, $\cos(2\pi j/p)<0$ iff $\frac{\pi}{2}<\frac{2\pi j}{p}<\pi$ iff $\frac{p}{4}<j<\frac{p}{2}$.
So we have $\left(\frac{2}{p}\right)=(-1)^{\lfloor\frac{p}{2}\rfloor-\lfloor\frac{p}{4}\rfloor}$.
We have the following cases:
If $p=8n+1$, then $\left(\frac{2}{p}\right)=(-1)^{4n-2n}=1$.
If $p=8n+3$, then $\left(\frac{2}{p}\right)=(-1)^{4n+1-2n}=-1$.
If $p=8n+5$, then $\left(\frac{2}{p}\right)=(-1)^{4n+2-(2n+1)}=-1$.
If $p=8n+7$, then $\left(\frac{2}{p}\right)=(-1)^{4n+3-(2n+1)}=1$.
So $2$ is a square modulo $p$ iff $p\equiv\pm1\pmod8$, or $\left(\frac{2}{p}\right)=(-1)^{(p^2-1)/8}$.