TITLE: Algebraic integers of $\mathbb{Q}(\sqrt{m})$ for $m$ a squarefree integer
QUESTION [6 upvotes]: I'm currently reading Marcus' "Number Fields," and I'm having difficulty proving the following result:
Corollary 2.2: Let $m$ be a squarefree integer. The set of algebraic integers in the quadratic field $\mathbb{Q}(\sqrt{m})$ is
$$ \left\{ a + b \sqrt{m} : a,b \in \mathbb{Z} \right\} $$
if $m \equiv 2,3 \pmod{4}$; and$$ \left\{ \frac{a+b\sqrt{m}}{2} : a,b \in \mathbb{Z} ~,~ a \equiv b \pmod{2} \right\}$$
when $m \equiv 1 \pmod{4}$. $\square$
It is easy enough to see that the claimed sets do, indeed, consist of algebraic integers. The other half of the proof proceeds something like this: suppose that $\alpha = r + s \sqrt{m}$ is an element of $\mathbb{Q}(\sqrt{m})$. Then $\alpha$ is a root of the polynomial
$$ x^2 - 2rx + r^2 - s^2m $$
In particular, this means that $\alpha$ is an algebraic integer if and only if both $2r$ and $r^2 - s^2 m$ are integers. At this point, the proof stops, and says that this implies the result. And therein lies the problem: I don't see how to make the connection. I do know, for example, that if one of $r,s$ is an integer, then the other one must be, too, i.e., either both are integers, or both are not. However, I cannot get any further than that. Can anyone give me a gentle nudge in the right direction? Thank you very much!

REPLY [3 votes]: In particular, this means that $\alpha$ is an algebraic integer if and only if both $2r$ and $r^2 - s^2 m$ are integers. 

This requires more work than what you've done so far. You need to further know that $x^2 - 2rx + (r^2 - s^2 m)$ is the minimal polynomial of $\alpha$. Fortunately this is clear as long as $s \neq 0$, which is the interesting case anyway.

I don't see how to make the connection. 

$2r$ is an integer; let's call it $n$. Then
$$r^2 - s^2 m = \frac{n^2}{4} - s^2 m$$
must also be an integer, or equivalently,
$$4r^2 - 4s^2 m = n^2 - (2s)^2 m \equiv 0 \bmod 4$$
must be an integer divisible by $4$. If $n$ is even, this means that $(2s)^2 m$ must be an integer divisible by $4$, or equivalently $s^2 m$ must be an integer, and since $m$ is squarefree this implies that $s$ must be an integer. (Otherwise, if the denominator of $s$ in lowest terms was $d$, then $m$ would have to be divisible by $d^2$.)
So the interesting case is when $n$ is odd, in which case $n^2 \equiv 1 \bmod 4$, and hence
$$(2s)^2 m \equiv 1 \bmod 4.$$
Since $m$ is squarefree this implies that $2s$ must be an integer, by the same argument as above, and moreover it must be an odd integer (so $s$ is half an odd integer, the same as $r$). It follows that $(2s)^2 \equiv 1 \bmod 4$, hence
$$m \equiv 1 \bmod 4.$$