Solution (source code)

= Solution

The <discriminant of a binary quadratic form> is $d=b^2-4ac$. If the form is <positive-definite>, evaluating it at $(1,0)$ gives $a>0$. For $a\ne0$, <completing the square> gives
$$
q(x,y)=a\left(x+\frac b{2a}y\right)^2+\frac{4ac-b^2}{4a}y^2.
$$
Evaluating along $x=-by/(2a)$ shows that positivity also requires $d<0$. Conversely these two inequalities make both displayed coefficients positive, proving
$$
\boxed{q\text{ is positive definite}\Longleftrightarrow a>0>d}.
$$
A <reduced positive definite binary quadratic form> satisfies $|b|\leq a\leq c$, with $b\geq0$ if $|b|=a$ or $a=c$. The last convention avoids counting both boundary representatives. For fixed negative <discriminant>, these inequalities imply
$$
|d|=4ac-b^2\geq3a^2,\qquad 1\leq a\leq\sqrt{|d|/3}.
$$
There are finitely many such integers $a$, finitely many integers $b$ with $|b|\leq a$, and then $c=(b^2-d)/(4a)$ is determined. Hence \b[the number of reduced forms is finite]. If no admissible integer coefficients have the given <discriminant>, this number is zero.

For $d=-39$, the bound gives $a=1,2,3$. The integrality of $c=(b^2+39)/(4a)$ and the boundary sign convention give respectively
$$
(a,b,c)=(1,1,10),\quad(2,1,5),(2,-1,5),\quad(3,3,4).
$$
These are all the <reduced positive definite binary quadratic forms of discriminant minus thirty-nine>. Thus
$$
\boxed{h(-39)=4},
$$
represented by $x^2+xy+10y^2$, $2x^2+xy+5y^2$, $2x^2-xy+5y^2$, and $3x^2+3xy+4y^2$.