General solution of Pell's equation If we know the minimal solution or any specific solution  of Pell's equation $x^2-ny^2=1$ , is there is any general formula to write all solution of Pell's equation?
 A: It's well know that the solution of the Pell's equation satisfy the reccurence relation:
$$x_{k+1} = x_1x_k + y_1ny_k$$
$$y_{k+1} = y_1x_k + x_1y_k$$
This was found by Brahmagupta and it holds because:
$$1 = (x_1 - ny_1)(x_k - ny_k) = (x_1x_k + y_1ny_k) - n(y_1x_k + x_1y_k)$$
A: $$a^2-db^2=\pm1\iff(a+b\sqrt d)(a-b\sqrt d)=\pm1\iff(a\pm b\sqrt d)\text{ are units in } \mathbb Q(\sqrt d)$$Hence the elementary theory of algebraic numbers gives all the solutions $(a_n,b_n)$ are given by the equations
$$(a_n+b_n\sqrt d)=(a_0+b_0\sqrt d)^n$$ and $$(a_n+b_n\sqrt d)=2^{1-n}(a_0+b_0\sqrt d)^n$$ according if $d\equiv 2,3\pmod 4$ and $d\equiv 1\pmod 4$ respectively and where $a_0+b_0\sqrt d$ is
the fondamental unit of the ring of integers of the quadratic field $\mathbb Q(\sqrt d)$.
A: Another way to understand this is that the solutions $(a,b)$ to $a^2-db^2=1$ are a subgroup of the group of units in the ring $\mathbb Z[\sqrt{d}]$, because the property $a^2-db^2=1$ is the assertion that the Galois norm $N(a+b\sqrt{d})$ of $a+b\sqrt{d}$ is $1$. The Galois norm is multiplicative, meaning that $N(\alpha\cdot \beta)=N(\alpha)\cdot N(\beta)$. It is a very special case of Dirichlet's Units Theorem that the group of such things, disregarding $\pm 1$, is a free abelian group on one generator. That is, everything of norm $1$ in that ring is $\pm(a_o+b_o\sqrt{d})^N$ for one fixed $a_o+b_o\sqrt{d}$ and integer exponent $N$. (This $a_o+b_o\sqrt{d}$ is called the "fundamental unit".)
Then the $a,b$ of solutions to Pell's equation are the rational part and coefficient of the irrational part in that power of the fundamental unit.
