Fundamental unit of the quadratic integer ring $\mathbb{Z}[\sqrt{n}]$ I looked in other questions but I didn't find any answers regarding quadratic integer rings. Apologies if I missed it.
Given the ring $\mathbb{Z}[\sqrt{n}]$ where $n$ is a square-free positive integer, I would like to find the fundamental unit (i.e. some $a + b\sqrt{n}$ such that $\langle a + b\sqrt{n}\rangle = \mathbb{Z}[\sqrt{n}]^\times$, the units of $\mathbb{Z}[\sqrt{n}]$). I do know if I take the smallest $y$ such that $ny^2$ is of the form $x^2 \pm 1$, I get a unit, $x + y\sqrt{n}$. After all, we have $ny^2 = x^2 \pm 1$, so $ny^2 - x^2 = \pm 1$, meaning that $N(x + y\sqrt{n}) = x^2 - ny^2 = \mp 1$ ($N$ is just a standard Euclidean function). Since this particular Euclidean function is also multiplicative we know that any power of $x + y\sqrt{n}$ is also a unit. However, this is where I get stuck. Is this $x + y\sqrt{n}$ indeed a fundamental unit? If so, how do I show it can generate all units? If not, how do I find the actual fundamental unit?
 A: In the case of a real quadratic field, the fundamental unit is the smallest unit of the form $ x + y \sqrt{d} $ such that $ x \geq 0 $ and $ y \geq 1 $. To see this, note that if $ x + y \sqrt{d} > 1 $ is a unit, we have that $ x^2 - dy^2 = \pm 1 $. Assume that $ x $ and $ y $ had different signs, then we would have
$$ x + y \sqrt{d} = \frac{\pm 1}{x - y \sqrt{d}} $$
and $ |x - y \sqrt{d}| \geq 1 $ since $ x $ and $ -y $ have the same sign.  This is a contradiction, therefore $ x $ and $ y $ are both nonnegative in $ x + y \sqrt{d} $. Since the fundamental unit is the smallest unit greater than $ 1 $, it follows that we may simply look at units of the form $ x + y \sqrt{d} $ where $ x, y $ are nonnegative, which reduces the problem to a necessarily finite brute force search.
While Dirichlet's unit theorem necessarily implies that the above found unit must be the fundamental unit, there is a more elementary proof of this fact. Assume that $ \varepsilon $ is the smallest unit greater than $ 1 $, and $ x $ is any unit greater than $ 1 $. We want to show that $ x $ is a power of $ \varepsilon $. Since the sequence $ a_n = \varepsilon^n $ diverges, there is a greatest integer $ n $ such that $ a_n = \varepsilon^n \leq x $. Then, $ x/\varepsilon^n $ is a unit $ \geq 1 $, but it is less than $ \varepsilon $ since $ x < \varepsilon^{n+1} $. By the definition of $ \varepsilon $, the only unit in the interval $ [1, \varepsilon) $ is $ 1 $, so it follows that $ x = \varepsilon^n $.
A more sophisticated algorithm to find the fundamental unit involves continued fractions, see these lecture notes for further information.
A: A very practical way to obtain the fundamental unit of a real quadratic field is as follows:
for $\Bbb Q(\sqrt d)$ we have
 $$a_n+b_n\sqrt d=(a_1+b_1\sqrt d)^n\Rightarrow b_{n+1}=a_1b_n+b_1a_n$$
This implies that the sequence $\{b_n\}$ is strictely increasing because $a_1,b_1,a_n,b_n$ are positive. Hence we can see at the sequence $d,2^2d,3^2d,4^2d,....$ and stop at the first term for which $db^2$ is such that $a^2-db^2=\pm1$ for some integer $a$. In this case the $a$ and $b$ are the searched $a_1$ and $b_1$ of the fundamental unit. This method as far as I know is due to Pierre Samuel.
Examples.- (1) For $\Bbb Q(\sqrt6)$ we have $6\cdot1=6;\space6\cdot2^2=24=5^2-1$ then the fundamental unit of $\Bbb Q(\sqrt6)$ is $5+2\sqrt6$.
(2) For $\Bbb Q(\sqrt7)$ we have $7\cdot3^2=63=8^2-1$ so the f. u. is $8+3\sqrt7$
A: It certainly has been discussed on MSE how to find a fundamental unit for the unit group of the ring of integers of a real quadratic number field $\mathbb{Q}(\sqrt{n})$. A nice survey, how to use continued fractions, and a table with examples for squarefree $n\le 21$ is given here.
Remark: The ring of integers in $\mathbb{Q}(\sqrt{n})$ is not always $\mathbb{Z}(\sqrt{n})$. This is only true for $n\equiv 2,3\bmod 4$. For the remaining case $n\equiv 1 \bmod 4$ (note that $n$ is squarefree), it is slightly different. An example here, with $n=141$ is discussed here on MSE. The result is as follows: since $\sqrt{141}=[11,\overline{1,6,1,22}]$, we have that $95+8\sqrt{141}$ is a fundamental unit!
