Calculating the positive and negative representations of the regular continued fraction of a quadratic irrational

This program finds the positive and negative representations of the regular continued fraction expansion of a quadratic irrational (u + t√d)/v, where d,t,u,v are integers, d >1 and nonsquare, t and v nonzero, as far as the end of the first period.
We use the continued fraction algorithm as described in K. Rosen, Elementary Number theory and its applications, 379-381 and Knuth's The art of computer programming, Vol. 2, p. 359.
The first reduced complete quotient ξi is located and this leads to the period ξi,...,ξi+j-1, which is printed in bold font.
We write (p,q) to denote (p + √d)/q.

(Also see MP313 lecture notes.)

Enter d (1 < d < 1015 and not a square):
Enter t (nonzero):
Enter u:
Enter v: (nonzero)

Last modified 17th March 2009
Return to main page