Take any square free $1 \neq n \in \mathbb{N}$ and recall that $R_n = \mathbb{Z}[\sqrt{n}]$ has a multiplicative norm function $N \colon R \to \mathbb{Z}$ given by $N(x + y\sqrt{n}) = x^2 -ny^2$ so a prime $p$ is of the required form iff $p$ is a norm in $R_n$ (i.e $p$ is in the image of $N$). Now take $n$ which is not $1$ mod $4$ (this assures that $R_n$ is the ring of integers of $\mathbb{Q}(\sqrt{n})$) and for which the class number of $\mathbb{Q}(\sqrt{n})$ is $1$ (equivalently, $R_n$ is a principal ideal domain). Clearly, $p = 2$ is of the required form for $n = 2$ ($x=2, y=1$), so assume $p$ is an odd prime number. Recall that $R_2$ is Euclidean with respect to $N$, so it is a principal ideal domain and $n = 2$ satisfies our assumptions. **Claim**: The ideal $(p)$ splits completely (is a product two distinct prime ideals) in $R_n$ iff $p$ is of the required form. **Proof**: We use the equivalent condition with the norm. If $p = IJ$ is a splitting, taking norms of ideals we see that $N(IJ) = p^2$ so since the ideals are proper, $N(I) = p$. Since $R_n$ is principal, there exists some $a \in R_n$ such that $(a) = I$. Therefore, $N(a) = N(I) = p$, and $p$ is a norm as required. If $p = N(x + y\sqrt{n})$, then $(p) = (x + y\sqrt{n})(x - y\sqrt{n})$ is the required splitting since the equality is obvious, and the primality of the factors follows from the fact that their norm is prime (equal to $p$). Furthermore the ideals are distinct as dividing a generator of one of them by a generator of the other does not belong to $R_n$. Now, according to Neukirch’s Algebraic Number Theory proposition (8.5) $(p)$ splits completely iff $n$ is a quadratic residue mod $p$. For $n = 2$ this amounts to $p = \pm 1 \pmod 8$, by a lemma of Gauss.