TITLE: Simplifying my Solution for: List the first three positive prime numbers $d$ in $\textbf{Z}$ so that the quadratic integers in...
QUESTION [5 upvotes]: Here is the question I have answered: 
List the first three positive prime numbers $d$ in $\mathbb{Z}$ so that the quadratic integers in $\mathbb{Q}(\sqrt{d})$ are precisely the ones of the form $a + b \sqrt d$, where $a$ and $b$ are rational integers. List the first three positive prime numbers $d$ so that the quadratic integers in $\mathbb{Q}(\sqrt{d})$ are precisely the ones of the form $$\frac{a + b
\sqrt d}{2},$$ where $a$ and $b$ are rational integers and $a$ and $b$ are either both even or both odd.
Do the same when $\sqrt d$ is replaced by $\sqrt{−d}$.
Here is my solution: 
If $$\frac{a + b \sqrt d}{c}$$ is an algebraic integer then its irreducible monic polynomial $f(X)$ in $\mathbb{Q}[X]$ has coefficients in $\mathbb{Z}$. Since conjugation : $\sqrt d \to -\sqrt d$ is a automorphism that fixes $\mathbb Q$ then $$\frac{a - b \sqrt d}{c}$$ is also a root of $f(X)$. So $$f(X) = \left(X - \frac{a + b \sqrt d}{c}\right)\left(X - \frac{a - b \sqrt d}{c}\right) = X^2 - 2 \frac{a}{c} X + \frac{a^2 - db^2}{4}.$$
i) $\frac{2a}{c}$ an integer implies $c = 1$ or $2$. 
ii) If $c = 2$ then $$\frac{a^2 - db^2}{4}$$ an integer implies $a^2 \equiv db^2 \bmod 4$. If $b$ is odd then so are $a$ and $d$ ($d$ is prime so either $2$ or odd)}. Working modulo $4$, $0 = (a - b)(a + b) = a^2 - b^2 = (d - 1)b^2 \bmod 4$, so that $d \equiv 1 \bmod 4$. 
When $d \equiv 3 \bmod 4$ or $2$ then clearly $\mathbb{Z}[\sqrt d]$ is a ring, i.e., closed under addition and multiplication. When $d \equiv 1 \bmod 4$ then $$\frac{1 + \sqrt d}{2^2} = \frac{1 + d^2}{2} + \frac{\sqrt d}{2},$$ and since $d^2 \equiv 1 \bmod 4$ then $\frac{1 + d^2}{2}$ in an odd integer, so again $$\mathbb{Z}\left[\frac{1 + \sqrt d}{2}\right]$$ is a ring closed under addition and multiplication. 
So the ring of integers in $\mathbb{Q}(\sqrt d)$ is $$\mathbb Z\left[\frac{1 + \sqrt d}{2}\right]$$ when $d \equiv 1 \bmod 4$, and $\mathbb Z[\sqrt d]$ when $d ≡ 3$ mod $4$, or $d = 2$. 
This means $5, 13,$ and $17$ are the first few primes where the ring of algebraic integers is of the form $$\mathbb Z\left[\frac{1 + \sqrt d}{2}\right],$$ and $-3, -7, -11$ the first few negative ones. $2, 3, 7, 11$ are the first few primes for $\mathbb Z[\sqrt d]$ and $-2, -5, -13$ the first few negative ones.
However, I am looking to find a simpler solution. Can someone post a solution that does not involve quadratic integer notions like  rings, fields, field extensions, splitting fields (I don't know how splitting fields could be used here in any circumstance, but I am not experienced enough to be able to say that with certainty). Thanks!

REPLY [3 votes]: I will try to fill in the hole skipped over by the first answerer. Well, he's right, it does take a lot of work to try to do it by elementary means.
Given $a, b \in \textbf Q$, and $d \in \textbf Z$ squarefree, what are the conditions necessary for $a^2 - db^2 = N \in \textbf Z$ to hold true?
If $a, b \in \textbf Z$, then $a^2 - db^2 = N \in \textbf Z$ is trivially true because $\textbf Z$ is closed under addition and multiplication.
If one or both of $a$ and $b$ are rational but not integers, things get a lot more complicated. To try to keep things simple, let's express $a$ and $b$ as fractions in lowest terms with positive denominators: $$a = \frac{p}{q}, b = \frac{r}{s},$$ $p, r \in \textbf Z$, $q, s \in \textbf Z^+$, $\gcd(p, q) = \gcd(r, s) = 1$.
Let us now further suppose that $q \neq s$. Then $$a^2 - db^2 = \frac{p^2 s^2}{q^2 s^2} - \frac{dr^2 q^2}{q^2 s^2}.$$ Although $d$ may seem to be a wildcard in all of this, remember that it is still squarefree. It may share prime factors with any of $p, q, r, s$, but we're guaranteed a deficit of factors and thus this number is not an integer.
Therefore $q = s$ is a must. Arbitrarily, I will ditch $s$ and use $q$ henceforth. Then $$a = \frac{p}{q}, b = \frac{r}{q}.$$ We need not worry about $q = 1$, this would mean $a, b \in \textbf Z$ and we already went over that.
Moving on to $q = 2$, we see that both $p$ and $r$ must be odd so as to not contradict the assertion that the two fractions are in lowest terms. Then we have $$a^2 - db^2 = \frac{p^2 - dr^2}{4}.$$ Since $p$ is odd, this means that $p^2 \equiv 1 \bmod 4$. Likewise, $r^2 \equiv 1 \bmod 4$. Then, for this thing to be an integer, we need $d \equiv 1 \bmod 4$ so that $p^2 - dr^2$ works out to be a multiple of $4$.
I still have left to prove that $q > 2$ fails to give integers. But it's almost the Sabbath now.