Find all primes $p$ such that $x^2=2$ has a solution in $\mathbb{Z}_p$. So, i found some primes with simple program: 7, 17, 23, 31, 41, 47, 71, 73, 79, 89, 97. But I cannot work out the pattern for it.
Please share any your ideas on the subject.
 A: By Euler's Theorem, we know that $(2|p)\equiv 2^{\frac{p-1}2}\pmod{p}$. Since, in your case $(2|p)=1\implies$ a prime number will be in your list if and only of $2^{\frac{p-1}2}=1$ in $\mathbb{Z}_p$

Thus, we get 

Reference: Tom Apostol's Introduction to Analytical Number Theory
A: Here it is a proof of 
$$ \left(\frac{2}{p}\right)=(-1)^{\frac{p^2-1}{8}} $$
i.e. that $2$ is a quadratic residue $\!\!\pmod{p}$ iff $p\equiv \pm 1\pmod{8}$, through field theory.

Let us consider the cyclotomic polynomial $\Phi_8(x)=x^4+1$ (i.e. the minimal polynomial of a primitive eighth root of unity) and its splitting field over $\mathbb{F}_p$. This field $\mathbb{K}$ is either $\mathbb{F}_p$ or $\mathbb{F}_{p^2}$ (meaning that $\Phi_8$ cannot be irreducible over $\mathbb{F}_p$) since $[\mathbb{K}:\mathbb{F}_p]$ equals the multiplicative order of $8\pmod{p}$, and for every odd prime $p^2\equiv 1\pmod{8}$.
If $p\equiv 1\pmod{8}$ we have that $\Phi_8(x)$ completely factors, so the conjugated roots $\frac{1\pm i}{\sqrt{2}}$ belong to $\mathbb{F}_p$ and so does their sum $\sqrt{2}$, giving $\left(\frac{2}{p}\right)=1$. A simpler alternative is given by the fact that $\mathbb{F}_p^*$ is a cyclic group with order $8k$.
If $p\equiv 3\pmod{8}$ we have that $\Phi_8(x)$ has two quadratic irreducible factors. By Frobenius automorphism, these factors are $(x-\zeta)(x-\zeta^3)$ and $(x-\zeta^5)(x-\zeta^7)$, i.e. $x^2-Ax-1$ and $x^2+Ax-1$ with $A=\sqrt{-2}$. We get $\left(\frac{-2}{p}\right)=1$, and since $\left(\frac{-1}{p}\right)=(-1)^{\frac{p-1}{2}}$ the multiplicativity of the Legendre symbol ensures $\left(\frac{2}{p}\right)=-1$.
If $p\equiv 5\pmod{8}$ we have that $\Phi_8(x)$ has two quadratic irreducible factors. By Frobenius automorphism, these factors are $(x-\zeta)(x-\zeta^5)$ and $(x-\zeta^3)(x-\zeta^7)$, i.e. $x^2-A$ and $x^2+A$ with $A=\sqrt{-1}$. We have that $A\in\mathbb{F}_p$ but $\zeta=\frac{1+A}{\sqrt{2}}\not\in\mathbb{F}_p$, so $\sqrt{2}\not\in\mathbb{F}_p$ and $\left(\frac{2}{p}\right)=-1.$
If $p\equiv 7\pmod{8}$ we have that $\Phi_8(x)$ has two quadratic irreducible factors. By Frobenius automorphism, these factors are $(x-\zeta)(x-\zeta^7)$ and $(x-\zeta^3)(x-\zeta^5)$, i.e. $x^2-Ax+1$ and $x^2+Ax+1$ with $A=\sqrt{2}$. This immediately leads to $\left(\frac{2}{p}\right)=1$ and finishes the proof.
