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
 A: 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$.
A: OK, to finish what you have started, which I believe is the question, you know that $\mathbb{Z}[\sqrt{-2}]$ is a principal ideal domain and thus a unique factorization domain. So given $p$, is it a prime in $\mathbb{Z}[\sqrt{-2}]$ ?
You have also that for $p\equiv 1,3(\mod 8)$ that 
$$a^2\equiv -2(\mod p)$$ meaning that 
$$p|a^2+2=(a+\sqrt{-2})(a-\sqrt{-2})$$ however $p\not |(a+\sqrt{-2})$ and 
$p\not |(a-\sqrt{-2})$, this contradicts the definition of prime so $p$ is not a prime in $\mathbb{Z}[\sqrt{-2}]$. Thus it has a factorization 
$$p=(x+y\sqrt{-2})(x-y\sqrt{-2}).$$
A: The theorem you're after is the Kummer-Dedekind theorem:

Theorem: Let $p$ be a prime, and let  $\beta\in \mathcal O_K$ be such that $K=\mathbb Q(\beta)$ and $p\nmid (\mathcal O_K:\mathbb Z[\beta])$. Let $f(X)$ be the minimal polynomial of $\beta$ over $\mathbb Q$. Suppose that 
  $$f(X) \equiv f_1(X)^{e_1}\cdots f_m(X)^{e_m}\pmod p. $$ 
  Then $p$ splits as $p\mathcal O_K = \mathfrak{p_1^{e_1}\cdots p_m^{e_m}}$ in $\mathcal O_K$.

In this case, when $p\equiv 1,3\pmod 8$, we see that $p$ splits completely in $K$. If $\mathfrak p$ is a prime dividing $p$, then $\mathfrak p$ has norm $p$. Moreover, since $K$ is a PID, $\mathfrak p=\langle a+b\sqrt{-2}\rangle$ for some $a,b\in\mathbb Z$. It follows that $p = N(\mathfrak p) = a^2+2b^2.$
