<s>[INST] Show every prime $p\equiv 1,3$ (mod 8) can be written as $p=x^2+2y^2$ 
Let $K=\mathbb{Q}(\sqrt{-2})$. Show that $\mathcal{O}(K)$ is a principal ideal domain. Deduce that every prime $p\equiv  1, 3$ (mod 8) can be written as $p = x^2 + 2y^2$ with $x, y \in \mathbb{Z}$.

As $−2$ is squarefree $6\equiv 1$ (mod 4) we have $\mathcal{O}(K) = \mathbb{Z}[
\sqrt{2}$]. The
discriminant is $\Delta$ = −8. The degree $n = 2$. The signature is $(0, 2)$. Thus the Minkowski bound is
$$ B_k = \frac{2!}{2^2}=\frac{4}{\pi}\times \sqrt{8} = \frac{4\sqrt{2}}{\pi}<2$$
Hence $Cl(K)$ is generated by the empty set of ideal classes and so $Cl(K) = \{1\}$. So this means $\mathcal{O}(K)$ is a principal ideal domain I believe...
Ok, now if we let $p \equiv 1$ or $3$ (mod 8). By quadratic reciprocity, $−2 ≡ \alpha^2$
(mod p) for
some integer $\alpha$. Thus
$$X^2 + 2 ≡ (X + \alpha)(X − \alpha) \quad\text{(mod}~~ p).$$
Ok, now I am slightly stuck, can we apply some theorem here? Not sure if what above is correct to get to the desired result
 [/INST] An elementary proof starting from scratch. If $p\equiv 1\pmod{8}$, in $\mathbb{F}_p^*$ there is an element with order $8$, which we may call $\alpha$. Since $\alpha^4+1=0$ we have $(\alpha+\alpha^{-1})^2=0 $ and $-2$ is a quadratic residue $\pmod{p}$. If $p\equiv 3\pmod{8}$ we may consider the degree of the splitting field of $\Phi_8(x)=x^4+1$ over $\mathbb{F}_p$, which is given by the least $k$ such that $8\mid(p^k-1)$, i.e. by $2$. So we have $\alpha\in\mathbb{F}_{p^2}$ with order $8$, and by Frobenius automorphism one of the quadratic factors of $x^4+1$ is given by 
$$(x-\alpha)(x-\alpha^3)=x^2-(\alpha+\alpha^3)-1$$
and the other quadratic factor is given by
$$(x-\alpha^5)(x-\alpha^7) = x^2-(\alpha^5+\alpha^7)-1.$$
On the other hand $(\alpha+\alpha^3)^2 = \alpha^2+\alpha^6-2 = -2$, so $-2$ is a quadratic residue in this case, too.
Let $u\in\{1,\ldots,\frac{p-1}{2}\}$ be such that $u^2+2\equiv 0\pmod{p}$. We have $u^2+2 = kp $ for some $k\in\{1,\ldots,\lfloor\frac{p}{4}\rfloor\}$. Let $v$ be the minimum between $u\pmod{k}$ and $(k-u)\pmod{k}$. We have $v^2+2=kq$ for some $q<k$ and by the Lagrange-Brahmagupta-Fibonacci identity
$$ (a^2+2b^2)(c^2+2d^2)= (ac+2bd)^2 + 2(bc-ad)^2 $$
we have
$$ (u^2+2)(v^2+2) = (uv+2)^2+2(v-u)^2 =k^2 pq.$$
On the other hand both $uv+2$ and $v-u$ are multiples of $k$, so by starting with a representation of a multiple of $p$ as $A^2+2B^2$ we got a representation as $A^2+2B^2$ of a smaller multiple
$$ \left(\frac{uv+2}{k}\right)^2+\left(\frac{v-u}{k}\right)^2 = qp $$
and the trick can be iterated again, ultimately leading to a representation of $p$ as $A^2+2B^2$.
</s>