Here is the theorem that I need to prove
For $K = \mathbb{Q}[\sqrt{D}]$ we have
$$\begin{align}O_K = \begin{cases} \mathbb{Z}[\sqrt{D}] & D \equiv 2, 3 \mod 4\\ \mathbb{Z}\left[\frac{1 + \sqrt{D}}{2}\right] & D \equiv 1 \mod 4 \end{cases} \end{align}$$
The theorem we need to use is this one that can be found in any generic number theory textbook.
an element $\alpha\in K$ is an algebraic integer if and only if its minimal polynomial has coefficients in $\mathbb{Z}$.
I tried many avenues of attack but it is extremely hard to prove. How do I prove it?
$\bullet$ Let $d \equiv 1 \mod 4.$
Let $A=x+y\sqrt{d} \in \mathcal O_K$ be arbitrary. We have
$(A-x)^2 - dy^2 = 0$. Expanding,
$A^2 -2xA +x^2 - dy^2 = 0$.
Now we use the fact that $m_A(x)$, the minimal polynomial of $A$, must be in $\Bbb Z[x]$: we must have $x=\frac{r}{2}$ for some $r \in \Bbb Z$.
Since $x^2 - dy^2 \in \Bbb Z$ too, we must have $y = \frac{s}{2}$.
So $x^2 - dy^2 = \frac{r^2}{4} -d\frac{s^2}{4}$.
This implies $r^2 - ds^2 \equiv r^2 - s^2 \equiv 0 \mod 4$.
So $r \equiv s \mod 2$, i.e. $r=s+2t$.
Putting this together, $A=\frac{r}{2} + \frac{s}{2}\sqrt{d} = t+s\frac{1+\sqrt{d}}{2}$ as required, showing that $\mathcal O_K = \Bbb Z[\frac{1+\sqrt{d}}{2}]$.
$\bullet$ Now assume $d \equiv 2 \mod 4$.
We can repeat the above argument, arriving at
$r^2 +2s^2 \equiv 0 \mod 4$.
The only solution is $(r, s) = (0, 0) \mod 4$, so in fact $x, y \in \Bbb Z$ and $\mathcal O_K = \Bbb Z[\sqrt{d}]$.
$\bullet$ For $d \equiv 3 \mod 4$ we have to consider $r^2 + s^2 \equiv 0 \mod 4$ and we come to the same conclusion as for $d=2$.