Imaginary quadratic field class number formula and class representatives

Compute the class number by formula

ClassNum[d_,opts___]:=Module[
{dd,w,verbose},

verbose=Verbose/.{opts}/.{Verbose->False};

chi[n_]:=Module[{},
JacobiSymbol[dd,n]
];

Lchi1:=Module[{},
-Pi/Abs[dd]^(3/2)Sum[chi[r]r,{r,1,Abs[dd]-1}]
];

If[d>0 || Not[SquareFreeQ[d]],
Return[False]
];

If[Mod[d,4]==1,dd=d,dd=4d];

w=2;If[dd==-4,w=4];If[dd==-3,w=6];

If[verbose,
{w Sqrt[Abs[dd]]Lchi1/(2Pi),Table[-w/Abs[dd]/2*chi[r]r,{r,1,Abs[dd]-1}]},
w Sqrt[Abs[dd]]Lchi1/(2Pi)
]
];

Compute representatives

ReducedPoints[n_]:=Module[
{Di,r,trr,Nr,c,d,count=1},
If[Mod[n,4]==1,Di=n,Di=4n];
r=(Di+Sqrt[Di])/2;
trr=Di;
Nr=Di(Di-1)/4;
For[c=1,c<=Floor[Sqrt[-Di/3]],c++,
For[d=Ceiling[(Di-c)/2],d<(Di+c)/2,d++,
If[((Di<2d && 4c^2<(Di-2d)^2-Di) ||(Di≥2d && 4c^2≤(Di-2d)^2-Di)) && Mod[Nr-trr d+d^2,c]==0 ,
Print["  ",count,". (c,d) = (",c,",",d,")"];If[c==1,Print["     class representative (r-d,c) = (1)"],
Print["     class representative (r-d,c) = (",Simplify[r-d],",",c,")"]
];
count++]
]
]
];

Report the class number and representatives over a range of imaginary quadratic fields

absnmin=1;absnmax=165;
For[n=-absnmin,n≥-absnmax,n--,
If[SquareFreeQ[n],
If[Mod[n,4]==1,Di=n,Di=4n];
r=(Di+Sqrt[Di])/2;
(*Print["(n, D, r) = (",n,",",Di,",",r,")"];*)
Print[Style["n = ",Bold],Style[n,Bold]];
Print["  ideal class number = ",ClassNum[n,Verbose->False]];
ReducedPoints[n]
];
];