Determining ring of integers for $\mathbb{Q}[\sqrt{17}]$

Theorem: If $d\equiv 1\pmod{4}$, then $\mathcal{O}_{\mathbf{Q}[\sqrt{d}]}=\mathbf{Z}\left[\frac{-1+\sqrt{d}}{2}\right]$. Otherwise, $\mathcal{O}_{\mathbf{Q}[\sqrt{d}]}=\mathbf{Z}[\sqrt{d}]$.

Proof: Let $\alpha=r+s\sqrt{d}\in\mathbf{Q}(\sqrt{d})$. Then, $\alpha\in\mathcal{O}_{\mathbf{Q}[\sqrt{d}]}$ iff $2r, r^2-s^2d\in\mathbf{Z}$. Clearly $2r\in\mathbf{Z}$, so $4s^2d\in\mathbf{Z}$, and since $d$ is squarefree, $2s\in\mathbf{Z}$. Substituting $m=2r, n=2s$, we get $r^2-ds^2\in\mathbf{Z}\implies 4|(m^2-dn^2)$. Now, if $d\equiv 2,3\pmod{4}$, then $$m^2-dn^2\equiv m^2+2n^2, m^2+n^2\pmod{4}.$$ Note that for these to be divisible by $4$, we must have that $m,n$ are both even, which happens iff $r,s\in\mathbf{Z}$, so this takes care of the case where $d\not\equiv 1\pmod{4}$.

Now if $d\equiv 1\pmod{4}$, then $m^2-dn^2\equiv m^2-n^2\pmod{4}$, but since $4|(m^2-n^2)$ iff $m\equiv n\pmod{2}$, we get $$\mathcal{O}_{\mathbf{Q}(\sqrt{d})}=\left\{\frac{m+n\sqrt{d}}{2}:m\equiv n\pmod{2}\right\}.$$ Now, note that $$\frac{1}{2}(m+n\sqrt{d})=\frac{m+n}{2}+n\left(\frac{-1+\sqrt{d}}{2}\right).$$ Since $m$ and $n$ have the same parity, $\frac{m+n}{2}$ is an integer, so $\mathcal{O}_{\mathbf{Q}(\sqrt{d})}\subset \mathbf{Z}+\frac{-1+\sqrt{d}}{2}\mathbf{Z}$, and to see the reverse just note that since $d$ is of the shape $4k+1$, $\frac{1}{2}(-1+\sqrt{d})\in\mathcal{O}_{\mathbf{Q}(\sqrt{d})}$, so we're done. $\Box$

$17\equiv 1\pmod{4}$, so $\mathcal{O}_{\mathbf{Q}[\sqrt{17}]}=\mathbf{Z}\left[\frac{-1+\sqrt{17}}{2}\right]$.


Let $D$ be a squarefree number. The element $a+b\sqrt{D}\in\Bbb Q(\sqrt{D})=K$ has minimal polynomial

$$x^2-2ax+(a^2-Db^2).$$

Thus $a+b\sqrt{d}\in{\cal O}_K\Leftrightarrow a\in\frac{1}{2}\Bbb Z,a^2-Db^2\in\Bbb Z$. If $b$ is not an integer, then can $a$ an integer? And, furthermore, what is the only possible denominator for $b$? Now try to show that $a,b$ can be the appropriate types of fractions if and only if $D$ is a quadratic residue mod $4$.