How to find a fundamental solution to Pell's equation? It is quite straightforward to find the fundamental solutions for a given Pell's equation when $d$ is small. But I am unable to solve this equation, as I'm unable to find the fundamental solutions:
Solve: $x^2-29y^2=1$ and $x^2-29y^2=-1$ with $y\not=0$.
Could you please guide me through the solution
 A: (Too long for a comment.)
If you're lucky and your discriminant $d$ has a certain form ($d = 5, 13, 21, 29, 53, 61, \dots$), you can use the smaller fundamental solutions of the Pell equation,
$$p^2-dq^2 = -4\tag{1}$$
Let,
$$\left(\frac{p+q\sqrt{d}}{2}\right)^3=u+v\sqrt{d}\tag2$$
$$\left(\frac{p+q\sqrt{d}}{2}\right)^6=x+y\sqrt{d}\tag3$$
then,
$$u^2-dv^2 = -1\tag4$$
$$x^2-dy^2 = 1\tag5$$
If fundamental $p,q$ are odd, then $(2),(3)$ are also fundamental. For your $d=29$, it is just $p,q = 5,1$. Hence the fundamental unit,
$$U_{29} =\tfrac{5+\sqrt{29}}{2}$$
and,
$$\big(U_{29}\big)^3=70+13\sqrt{29},\quad \text{thus}\;\;\color{blue}{70}^2-29\cdot\color{blue}{13}^2=-1$$
$$\big(U_{29}\big)^6=9801+1820\sqrt{29},\quad \text{thus}\;\;\color{blue}{9801}^2-29\cdot1820^2=1$$
$$2^6\left(\big(U_{29}\big)^6+\big(U_{29}\big)^{-6}\right)^2 =\color{blue}{396^4}$$
Incidentally, since certain eta quotients involve $U_{29}$, we find those integers all over Ramanujan's famous pi formula,
$$\frac{1}{\pi} = \frac{2 \sqrt 2}{\color{blue}{9801}} \sum_{k=0}^\infty \frac{(4k)!}{k!^4} \frac{29\cdot\color{blue}{70\cdot13}\,k+1103}{\color{blue}{(396^4)}^k}$$
Nice, eh?
A: The standard method for finding the fundamental solution is continued fractions for $\sqrt {29},$ and would not be difficult with a calculator. HERE is a summary using $\sqrt 7$ instead.  Gauss and Lagrange made an equivalent but better method with "reduced" quadratic forms, that requires no decimal accuracy for the square root, just the integer part, just integer arithmetic, and no "cycle detection." I have described it often on this site.
http://zakuski.utsa.edu/~jagy/BLOG_2014_July_15.pdf
jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$ ./Pell 29


0  form   1 10 -4   delta  -2
1  form   -4 6 5   delta  1
2  form   5 4 -5   delta  -1
3  form   -5 6 4   delta  2
4  form   4 10 -1   delta  -10
5  form   -1 10 4   delta  2
6  form   4 6 -5   delta  -1
7  form   -5 4 5   delta  1
8  form   5 6 -4   delta  -2
9  form   -4 10 1   delta  10
10  form   1 10 -4



 Pell automorph 
9801  52780
1820  9801

Pell unit 
9801^2 - 29 * 1820^2 = 1 

=========================================

Pell NEGATIVE 
70^2 - 29 * 13^2 = -1 

=========================================

  4 PRIMITIVE 
27^2 - 29 * 5^2 = 4 

=========================================

  -4 PRIMITIVE 
3775^2 - 29 * 701^2 = -4


NOTE by hand:  5^2 - 29 * 1^2 = -4 
was passed over by my program; that's life. 

=========================================

Well. The general, reliable method is continued fractions. Doing these with an ordinary calculator for $\sqrt n$ will work nicely for most small $n.$ However, as you can check in various places, this becomes problematic for $\sqrt {61}.$ You can switch to continued fractions with large decimal accuracy on computer, but eventually one runs into problems. The method above is very similar to continued fractions, it just has a more careful style of bookkeeping, with the result that it always works. The fundamental theorem here is due to Lagrange, I will put a jpeg from a 1929 book by L. E. Dickson, it is Theorem 85. Notice that everyone is now using LED light bulbs, that can't be a coincidence.

