TITLE: How many elements in a number field of a given norm?
QUESTION [22 upvotes]: Let $K$ be a number field, with ring of integers $\mathcal{O}_k$.  For $x\in \mathcal{O}_K$, let $f(x) = |N_{K/\mathbb{Q}}(x)|$, the (usual) absolute value of the norm of $x$ over $\mathbb{Q}$.  Dirichlet's unit theorem tells us, in a precise sense, "how many" units (i.e., elements with $f(x)=1$) there are in $\mathcal{O}_K$.
My question is, are there results out there about the size (or structure) of the set of elements $\alpha\in \mathcal{O}_K$ with $f(\alpha)=n$, for some given positive integer $n$?  (To make things more concrete, we could just focus on $n=2$, if it helps.)
Of course, if $f(\alpha)=n$ and $u$ is a unit, $f(u\alpha)=n$ too, so we should mod out by the action of $\mathcal{O}_K^*$ on $\mathcal{O}_K$ by multiplication, i.e., look at equivalence classes of associated elements of $\mathcal{O}_K$.  If we let $S =$ this set of equivalence classes, $f$ is well-defined on $S$.  For a given $n\in\mathbb{N}$, is $f^{-1}(n)$ finitely generated or (dare I hope it) finite?

REPLY [5 votes]: This is an addendum to Addendum 2 in Bruno's great answer.
Let $d$ be a square free integer, let $K$ be the quadratic field $\mathbb Q(\sqrt d)$, let $\mathbb Z_K$ be its ring of integers, and let $D$ be the integer which equal to $d$ if $d\equiv1\bmod4$, and to $4d$ otherwise.
Following
Borevich-Shafarevich, Number Theory, p. 237,
Borevitch-Chafarevitch, Théorie des Nombres, p. 263,
define $\chi:\mathbb Z\to\mathbb Z$ as follows. If $x$ is not prime to $D$, put $\chi(x)=0$. If $x$ is prime to $D$, let
$$d\equiv1\bmod4\implies\chi(x)=\left(\frac{x}{|d|}\right),$$
$$d\equiv3\bmod4\implies\chi(x)=(-1)^{(x-1)/2}\left(\frac{x}{|d|}\right),$$
$$d=2d'\implies\chi(x)=(-1)^{[(x^2-1)/8]+[(x-1)/2]+[(d'-1)/2]}\left(\frac{x}{|d'|}\right),$$
where $(\frac{a}b)$ is the Jacobi symbol.
Then $\chi$ induces a multiplicative map from $\mathbb Z/D\mathbb Z$ to $\mathbb Z$. Moreover, if $p$ is prime, then
$\bullet$ $\chi(p)=1$ if $p\mathbb Z_K$ is the product of two prime ideals of norm $p$,
$\bullet$ $\chi(p)=-1$ if $p\mathbb Z_K$ is a prime ideal of norm $p^2$,
$\bullet$ $\chi(p)=0$ if $p\mathbb Z_K$ is the square of a prime ideal of norm $p$.
This implies
$$
\zeta_K(s)=\zeta(s)\ L(s,\chi),
$$
that is
$$
\text{(Dedekind)}=\text{(Riemann)}\cdot\text{(Dirichlet)},
$$
and the number of ideals of $\mathbb Z_K$ of norm $n$ is
$$
\sum_{m|n}\ \chi(m).
$$
Now assume $d < 0$.
$(*)$ The number $u$ of units of $\mathbb Z_K$ is $4$ if $d=-1$, it is $6$ if $d=-3$, and it is $2$ otherwise.
See for instance this entry of PlanetMath.
Suppose in addition that $\mathbb Z_K$ is principal, i.e. that $d$ is one of the numbers
$$-1, -2, -3, -7, -11, -19, -43, -67, -163.$$
See for instance this sub-entry of Wikipedia.
The number of elements of norm $n$ is then
$$
u\ \sum_{m|n}\ \chi(m),
$$
where $u$ is the number of units of $\mathbb Z_K$, see $(*)$.