TITLE: Given $d \equiv 1 \pmod 4$, can $\mathcal{O}_{\mathbb{Q}(\sqrt{d})}$ have a fundamental unit that is not a "half-integer"?
QUESTION [5 upvotes]: Also $d > 0$, $\mu(d) \neq 0$.
I acknowledge the term "half-integer" is, at best, problematic. What I mean by it is that an integer in $\mathcal{O}_{\mathbb{Q}(\sqrt{d})}$ is of the form $\frac{a + b \sqrt{d}}{2}$ with $a$ and $b$ both odd.
Please bear with me, I'm very new to this subject. If I've done it correctly, the fundamental units in $\mathcal{O}_{\mathbb{Q}(\sqrt{d})}$ for $d = 5, 13, 17, 21$ are $$\frac{1 + \sqrt{5}}{2}, \frac{3 + \sqrt{13}}{2}, \frac{5 + 3 \sqrt{17}}{2}, \frac{5 + \sqrt{21}}{2}.$$
Can the fundamental unit in such a domain possibly be of the form $a + b \sqrt{d}$ rather than $\frac{a + b \sqrt{d}}{2}$? And if so, when factoring other integers in that domain, how can you be sure you haven't overlooked a "half-integer" factor?

EDIT: It's been pointed out that I screwed up the calculation in $\mathcal{O}_{\mathbb{Q}(\sqrt{17})}$. Still, I appreciate any insights you all might have regarding fundamental units in these domains.

REPLY [5 votes]: Yes, it can. An arithmetic mistake on your part has masked an example you would otherwise have found yourself. Verify that $$N\left(\frac{5}{2} + \frac{3\sqrt{17}}{2}\right) = \frac{25}{4} - \frac{153}{4} = -32.$$
In order for $\mathcal{O}_{\mathbb{Q}(\sqrt{d})}$ to have a half-integer fundamental unit, there has to be a solution to $x^2 - dy^2 = \pm 4$ with $x$ and $y$ both odd, and there isn't when $d = 17$. Consider this modulo 16: the odd squares are 1 and 9, and since $17 \equiv 1 \pmod{16}$, we see that $1 - 1 = 0$, $1 \pm 9 = 8$, $9 - 9 = 0$. But $4 \not\equiv 0$ nor $8 \pmod{16}$. Hence the fundamental unit of $\mathcal{O}_{\mathbb{Q}(\sqrt{17})}$ is $4 + \sqrt{17}$.
At least for primes $p$ what you can do is see whether you can solve $x^2 - dy^2 = \pm 4p$ with $x$ and $y$ odd. For composite numbers, you take this to the constituent prime factors, but if $\mathcal{O}_{\mathbb{Q}(\sqrt{d})}$ is not UFD then you also have to watch out for potentially multiple distinct factorizations, as well as non-obviously non-distinct factorizations (fun, right?).
Finding the fundamental unit of a particular real quadratic integer ring is something your favorite computer algebra system can do much more quickly and reliably than you can. For example, with Wolfram Mathematica you can do NumberFieldFundamentalUnit[Sqrt[n]] (I believe this also works in Wolfram Alpha).
Let me give you an example that is neither one more than a power of 2 nor one more than a square: given $d = 41$, we have $32 - 5\sqrt{41}$ as the fundamental unit.