Integers of the form $x^2+2y^2$. I'm stuck in the following problem:
prove an integer $n$ is of the form $x^2+2y^2$ if and only if every prime divisor $p$ of $n$ that is congruent to $5$ or $7\bmod8$ appears with an even exponent.
I think we have to do something similar to Fermat’s sum of two squares theorem. So far I have only managed to see that the product of two numbers of this form is a number of this form (this was seen via the Fibonacci Brahmagupta identity).
 A: It suffices to show that every prime 1 or 3 mod 8 can be expressed in this form. Start by showing that a solution exists modulo $p$, then extend this to the integers by an application of Minkowski's Theorem.
A: If $x^2 + 2y^2 ≡ 0 \pmod p$ and $\left(\frac{−2}{p}\right) = −1$ implies that both $x, y \equiv 0 \pmod p$ and $x^2 + 2y^2 \equiv 0 \pmod {p^2}$ .
Here $\left(\frac{−2}{p}\right)$ is the Legendre symbol. Also note that $$\left(\frac{−2}{p}\right) = (-1)^{\frac{p^2 - 1}{8} + \frac{p - 1}{2}}.$$ From here you can conclude that $\left(\frac{−2}{p}\right) = −1$ if and only if $p$ is of the form $5$ or $7 \bmod 8$.
For the converse case see here.
A: The squares modulo 8 are 1, 4, 1, 0, 1, 4, 1, 0 and twice the squares modulo 8 are 2, 0, 2, 0, 2, 0, 2, 0. Therefore, $x^2 + 2y^2 \equiv 0, 1, 2, 3, 4$ or $6 \pmod 8$. So if a prime $p \equiv 5$ or $7 \pmod 8$ then it can't be of the form $x^2 + 2y^2$.
So far I have only used elementary methods, and maybe the rest of what I'm thinking can be accomplished without recourse to algebraic number theory. But since you tagged this question with that tag, I will go ahead and avail myself to the methods of algebraic number theory. I don't know how much you know about it, and I certainly can't claim to be an expert. Please bear me with me if I seem to be repeating basic facts you already know.
If $a$ and $b$ are integers in the usual sense, then $$(a - b\sqrt{-2})(a + b\sqrt{-2}) = a^2 + 2b^2.$$ Essentially we have computed the algebraic norm of $a \pm b\sqrt{-2}$, both of which are algebraic integers in the ring $\mathbb{Z}[\sqrt{-2}]$, and their product (this norm) is an integer in the usual sense (a whole, purely real rational number). All numbers in $\mathbb{Z}[\sqrt{-2}]$ are of the same form as $a \pm b\sqrt{-2}$, and the product of any numbers in this ring is also a number in this ring, which is another way of saying this ring is closed under multiplication.
Since $b$ can be 0, all purely real rational integers (notated $\mathbb{Z}$ or $\textbf{Z}$) are in this ring. But certain prime numbers from $\mathbb{Z}$ are "composite" in $\mathbb{Z}[\sqrt{-2}]$:


*

*$2 = (-1)(\sqrt{-2})^2$

*$3 = (1 - \sqrt{-2})(1 + \sqrt{-2})$

*$11 = (3 - \sqrt{-2})(3 + \sqrt{-2})$

*$17 = (3 - 2\sqrt{-2})(3 + 2\sqrt{-2})$

*$19 = (1 - 3\sqrt{-2})(1 + 3\sqrt{-2})$

*etc.


Obviously, numbers like 5 or 7, which are prime in $\mathbb{Z}$ are still prime in $\mathbb{Z}[\sqrt{-2}]$ (they are inert primes). These inert primes can't be expressed as $a^2 + 2b^2$.
But if $p \equiv 5$ or $7 \pmod 8$ and $\alpha$ is even, then $p^\alpha = (p^{\frac{\alpha}{2}})^2$. Assign $q = p^{\frac{\alpha}{2}}$. Then $p^\alpha = (q - 0\sqrt{-2})(q + 0\sqrt{-2})$. To satisfactorily solve the problem you still need to prove what happens when $\alpha$ is odd, but I'm confident you can figure this out for yourself.
I'd like to close with a couple of examples:


*

*$3 \times 5 = (1 - \sqrt{-2})(1 + \sqrt{-2})5$

*$3 \times 5^2 = (1 - \sqrt{-2})(1 + \sqrt{-2})5^2 = (5 - 5\sqrt{-2})(5 + 5\sqrt{-2}) = 5^2 + 2 \times 5^2 = 75.$

