Let $n$ be a square-free integer, and consider the quadratic number field $k=\mathbb{Q}(\sqrt{n})$; prove that $\alpha=a+b\sqrt{n} \in \mathbb{Q}(\sqrt{n})$ is integral over $\mathbb{Z}$ iff $a, b \in \mathbb{Z}$ or $n \equiv 1 \bmod 4$ and $a \equiv b \equiv 1/2 \bmod \mathbb{Z}$.
$\Leftarrow$ is easy, but I know not how to do $\Rightarrow$.
This exercise is interesting because shows
- If $n \not \equiv 1 \bmod \,4$ then $O_k=\mathbb{Z}[\sqrt{n}]$
- If $n \equiv 1 \bmod \, 4$ then $O_k=\mathbb{Z}[(1+\sqrt{n})/2]$.
$\alpha=a+b\sqrt n$ is integral means $\alpha$ is a root of a monic polynomial with integer coefficients: $(x-(a+b\sqrt n))(x-(a-b\sqrt n))=x^2-2ax+(a^2-nb^2)$, so $2a$ and $a^2-nb^2$ are integers. Can you take it from here? Note that $0$ and $1$ are the quadratic residues modulo $4. $