Even though some of the main ideas have been pointed out above, I will try to add (in all modesty) a complete answer.

The following outline comes from my master thesis and further develops some of the ideas in David Cox's book *Primes of the form $x^2+ny^2$*.

$\color{red}{\text{PART 1: Preliminary results on the genus field.}}$

**Lemma:** Given a number field $K$, there is a one-to-one correspondence between unramified Abelian extensions $M$ of $K$ and subgroups $H$ of the ideal class group $C(\mathcal{O}_K)$. Furthermore, if the extension $K \subset M$ corresponds to the subgroup $H \subset C(\mathcal{O}_K)$, then the Artin map induces an isomorphism
$$C(\mathcal{O}_K)/H \xrightarrow{\sim} \mathrm{Gal}(M/K)$$

*Proof.* See Corollary 5.21 in Cox for the details.

**Definition:** The genus field $M$ is the unramified Abelian extension of $K$ corresponding to the subgroup $C(\mathcal{O}_K)^2 \subset C(\mathcal{O}_K)$.

Possibly there are other definitions for the genus field, but it can be shown that the above definition implies the following characterization:

**Theorem:** Let $K$ be an imaginary quadratic field of discriminant $d_K$. Let $\mu$ be the number of primes dividing $d_k$ and let $p_1, \ldots, p_r$ be the odd primes dividing $d_K$. (So that $\mu=r$ or $r+1$ according to whether $d_K \equiv 0 \textrm{ or } 1 \bmod{4}$). Set $p_i^*=(-1)^{(p_i-1)/2}p_i$. Then:

- The genus field of $K$ is the maximal unramified extension of $K$ which is an Abelian extension of $\mathbb{Q}$.
- The genus field $M$ of $K$ is $K(\sqrt{p_1^*}, \ldots, \sqrt{p_r^*})$ and $[M:\mathbb{Q}]=2^{\mu}$.

*Proof.* See Theorem 6.1 in Cox for the details.

$\color{red}{\text{PART 2: When is the Genus field equal to the HCF?}}$

**Lemma 1:** The Hilbert class field $L$ of $K=\mathbb{Q}(\sqrt{-n})$ is Abelian and Galois over $\mathbb{Q}$ (besides being Galois over $K$) if and only if the genus field equals the Hilbert class field

*Proof.* It can be shown that $[G,G]=C(\mathcal{O}_K)^2$ with $G=\mathrm{Gal}(L/\mathbb{Q})$ (see Theorem 6.1 in Cox). So if $\mathrm{Gal}(L/\mathbb{Q})$ is Abelian then $C(\mathcal{O}_K)^2=1$ and via Galois theory of unramified Abelian extensions this gives:
$$C(\mathcal{O}_K)/1 \xrightarrow{\sim} \mathrm{Gal}(M/K)$$
But the left hand side corresponds to $\mathrm{Gal}(L/K)$ via Artin Reciprocity, so that
$$[L:K]=|\mathrm{Gal}(L/K)| = |\mathrm{Gal}(M/K)|=[M:K]$$
Since we already know that $M \subset L$, we actually have $M = L$.

Before we continue, we recall the following result:

**Lemma 2:** Let $K$ be an imaginary quadratic field and let $L$ be Hilbert class field of $K$. Then $L$ is a Galois extension of $\mathbb{Q}$, and its Galois group can be written as a semidirect product
$$\mathrm{Gal}(L/\mathbb{Q}) \cong \mathrm{Gal}(L/K) \rtimes (\mathbb{Z}/2\mathbb{Z})$$
where the nontrivial element of $\mathbb{Z}/2\mathbb{Z}$ acts on $\mathrm{Gal}(L/K)$ by sending $\sigma$ to its inverse element $\sigma^{-1}$.

*Proof.* See p122 in Cox for the details.

**Lemma 3:** Let $H$ and $K$ be two finite groups. Then $H\rtimes_\theta K$ is abelian if and only if $H$ and $K$ are abelian and $\theta$ is the trivial homomorphism.

*Proof.* Sufficiency is obvious. For necessity, if $\theta$ is nontrivial, then some $k\in K$ maps to some $\operatorname{id}\ne \theta_k\in \operatorname{Aut}(H)$, which means that $\theta_k(h)\ne h$ for some $h\in H$. Thus $hk=k\theta_k(h)\ne kh$, so we have two elements that do not commute.

**Theorem 1:** The Hilbert class field $L$ of $K=\mathbb{Q}(\sqrt{-n})$ is Abelian if and only if $CL(K) \cong (\mathbb{Z}/2\mathbb{Z})^r$ for some $r \geq 0$.

*Proof.* From the two previous lemmas it follows that $\mathrm{Gal}(L/\mathbb{Q})$ is abelian if $\mathrm{Gal}(L/K)$ is abelian, and $\sigma$ acts trivially. The last condition is only possible if for every element of $\sigma \in \mathrm{Gal}(L/K)$ we have $\sigma=\sigma^{-1}$. But this means that $\sigma^2=1$ for every $\sigma$, such that $\mathrm{Gal}(L/K)$ must be an elementary abelian $2$-group (i.e. of the form $\mathbb{Z}/2\mathbb{Z}^r$ for some $r \geq 0$). Under these assumption, the second requirement, that $\mathrm{Gal}(L/K)$ must be abelian, is automatically satisfied. Because of Artin reciprocity we now have that
$$CL(K) \cong \mathrm{Gal}(L/K) \cong (\mathbb{Z}/2\mathbb{Z})^r$$
and we are done.

**Definition:** Let $K=\mathbb{Q}(\sqrt{-n})$ be an imaginary quadratic field. Then we call the positive integer $n$ a convenient number if the class group of $K$ is an abelian $2$-group, i.e. $CL(K)=(\mathbb{Z}/2\mathbb{Z})^r$ for some $r \geq 0$.

But which numbers $n$ are convenient numbers? Euler discovered that the following 65 idoneal numbers are convenient numbers.

Weinberger proved in 1973 that at most one other convenient number can exist, and that if the generalized Riemann hypothesis holds, then the list is complete.

Combining Lemma 1 and Theorem 1, we have:

**Theorem 2:** The genus field equals the Hilbert Class field of $K=\mathbb{Q}(\sqrt{-n})$ if and only if the class group of $K$ is an abelian $2$-group if and only if $n$ is one of Euler's 65 idoneal numbers or Weinberger's (conjectured, unique) 66th number.

$\color{red}{\text{PART 3: Primes of the form $x^2+ny^2$ and congruence relations.}}$

Another curious fact of Euler's idoneal numbers is that they are very closely related to situations in which congruences can be used to express the necessary and sufficient conditions for a prime to be of the form $p=x^2+ny^2$. More specifically,

**Theorem 3:** Let $n$ be a convenient number. Then the necessary and sufficient conditions for a prime to be expressed as $p=x^2+ny^2$ can be stated by congruence relations.

Before we can prove this claim we need the following lemma

**Lemma 4:** Let $n$ be one of Euler's 65 convenient numbers such that the genus field of $K=\mathbb{Q}(\sqrt{-n})$ equals the Hilbert class field. Since the genus field is given by
$$M=K(\sqrt{p_1^*}, \sqrt{p_2^*}, \ldots, \sqrt{p_n^*})$$
the HCF can be written as a composite of quadratic fields
$$L=K_0 K_1 K_2 \cdots K_n$$
with $K_i=\mathbb{Q}(\sqrt{p_i^*}$) for $i \geq 1$, and $K_0=K$. Moreover, a prime $p$ splits completely in $L$ if and only if it splits completely in all of the $K_i$.

and the following major result

**Theorem 4:** A prime can be represented as $p=x^2+ny^2$ if and only if the prime $p$ splits completely in the HCF of $\mathbb{Q}(\sqrt{-n})$.

*Proof.* See Theorem 5.26 in Cox.

We can now start proving Theorem 3:

*Proof.* If $n$ is one of Euler's 65 convenient numbers, then Lemma 4 argues that the HCF can be written as the composite field of extensions $\mathbb{Q}(\sqrt{p_i^*})$ over $\mathbb{Q}$ and that a prime splits completely over the composite field if and only if it splits completely over all the fields $\mathbb{Q}(\sqrt{p_i^*})$. So, Theorem 4 can now be reread as follows: a prime can be expressed in the form $p=x^2+ny^2$ iff $p$ splits completely in the HCF iff $p$ splits completely over all the $K_i$. Using Dedekind's theorem on the splitting behavior in quadratic extensions, this just means that $\left(d_{K_i}/p\right)=1$ for all $i$. Each condition gives us a congruence relation. Taking the different congruences together, we can conclude that the necessary and sufficient conditions can be expressed by congruence relations.

**Corollary:** Let $n$ be a convenient number. Let $q_i$, for $i=1, \ldots, r$ be the odd divisors of $n$ and set $q^* = (-1)^{(q-1)/2}$. Then
$$p=x^2+ny^2 \Leftrightarrow \left( \frac{-n}{p} \right) = 1 \textrm{ and } \left( \frac{q_1^*}{p} \right) = \left( \frac{q_2^*}{p} \right) = \cdots = \left( \frac{q_r^*}{p} \right) = 1$$

*Example.* The above theory gives us a very easy way to find congruence relations when $n$ is a convenient number: just take any number Euler's list and find the divisors, .e.g.
\begin{eqnarray*}
p=x^2+93y^2 &\Leftrightarrow& \left( \frac{-93}{p} \right) = \left( \frac{-3}{p} \right) = \left( \frac{-31}{p} \right) = 1 \\
&\Leftrightarrow& p \equiv 1, 25, 49, 97, 109, 121, 133, 157, \\
&& \ \ \ \ \ \ \ 169, 193, 205, 253, 289, 349, 361 \mod{372}
\end{eqnarray*}