Finding the class number h(d) of a real quadratic field

Here d > 1 is squarefree.
Here D is the field discriminant.
We locate all reduced irrationals of the form (b+√D)/(2|c|), where c is negative and 4c divides D-b2. We use the PQa continued fraction algorithm of Lagrange to break the set into disjoint cycles, retaining one number from each cycle. Each reduced number then gives rise to a reduced form (a,b,c) of discriminant D, where a=(b2-D)/(4c).
We are able to also determine if the Pell equation x2-Dy2=-4 has a solution, by using the fact that the equation is soluble iff at least one of the above cycles is odd.

(See note and Henri Cohen's A course in computational number theory, page 260, First Edition.)

Enter d (d > 1 and squarefree, d < 1010 ):

Last modified 13th May 2003
Return to main page