Calculating the class number h(d) for real quadratic fields Q(√d)

h(d) is listed for all squarefree d in the range m ≤ d ≤ n, where n < 106.
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.

We write the output as h(d)- or h(d)+, according as the negative Pell equation is, or is not, soluble.

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

Enter m (1 ≤ m < 106 ):
Enter n (1 ≤ m ≤ n < 106 ):

Last modified 18th July 2011
Return to main page