Project Euler 64 - Odd Period Square Roots

Official link: https://projecteuler.net/problem=64

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: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Continued_fraction_expansion

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: http://web.math.princeton.edu/mathlab/jr02fall/Periodicity/alexajp.pdf

Interactive Code

Enter an integer (yourinput)

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