Sum of three squares and class numbers of imaginary quadratic fields