Exhibit an algebraic integer in a quadratic integer ring having a given norm and trace

Find an algebraic integer $\alpha \in \mathbb{Q}(\sqrt{D})$ having norm 31 and trace 17.

Let $\alpha = a+b\sqrt{D}$ and $\overline{\alpha} = a-b\sqrt{D}$. Now $N(\alpha) = \alpha\overline{\alpha} = a^2 - Db^2$ and $\mathsf{tr}(\alpha) = \alpha + \overline{\alpha} = 2a$. We wish to find $a$, $b$, and $D$ such that $a+b\sqrt{D}$ is an algebraic integer, $a^2-Db^2 = 31$, and $2a = 17$. If such an integer exists, then $a = \frac{17}{2}$ is a half-integer- in particular, we must have $D \equiv 1$ mod 4. Substituting, and letting $b = \frac{b_0}{2}$, we have $Db_0^2 = 165 = 3 \cdot 5 \cdot 11$. Thus $D = 165$ and $b_0 = \pm 1$, so that $b = \pm \frac{1}{2}$. Indeed, we can verify that $N(\frac{17}{2} + \frac{1}{2}\sqrt{165}) = 31$ and $\mathsf{tr}(\frac{17}{2} + \frac{1}{2}\sqrt{165}) = 17$.