Project Euler 64 - Odd Period Square Roots

Official link:

I am not happy with my Solution as I do not fully understand why my algorithm works

Thought Process

Key here is finding a fast and accurate way to generate the continued fraction of a number, look at the following:

We obtain the following algorithm: (The code for finding the continued fraction will be in my Essential Functions)

We will continue this until we have found an a(n) = 2*root, as this implies that from here the continued fraction will repeat. The proof for this is in Corollary 3.3 of the following article:

Interactive Code

Enter an integer (yourinput)

Code will output number of continued fractions that have an odd period less than yourinput