The problem in Project Euler #64 asks us to generate continued fractions for square roots of integers.
The basic way to do it is:
A fraction
$\frac{\sqrt{n} + b}{d}$ can be expanded to:
$$
1 + \frac{1}{\frac{d}{\sqrt{n}+b}}
$$
$$
1 + \frac{1}{\frac{\sqrt{n}-b}{(\frac{n - b^2}{d})}}
$$
The next step involves factorizing $\frac{\sqrt{n}-b}{(\frac{n-b^2}{d})}$ to $$ a + \frac{\sqrt{n}+b'}{d'} $$ where $$ d' = (\frac{n-b^2}{d}) \\ a = \left \lfloor{\frac{\sqrt{n}-b}{(\frac{n-b^2}{d})}}\right \rfloor \\ b' = -b - ad' $$
Overall: $$ 1 + \frac{1}{\frac{d}{\sqrt{n}+b}} = 1 + \frac{1}{a + \frac{\sqrt{n}+b'}{d'}} $$
After this you repeat the steps on $\frac{\sqrt{n}+b'}{d'}$ to get the next fraction.
However in the expression $d' = \frac{n-b^2}{d}$, it is observed that $n-b^2$ is always evenly divisible by $d$ (remainder is $0$).
This greatly simplifies the problem. I'm however, stuck at why this property will always hold. I'm hoping you could help me with the proof.
Thank you for your help.