One of Jacobi's theorem states that the number of representations of a positive integer $n$ as a sum of two squares of integers equals
$$4(d_1(n)-d_3(n)),$$
where the function $d_i$ counts the number of positive integer divisors congruent to $i \mod{4}$ of $n$.

My question is whether there are similar formulas for representations by the quadratic form $x^2+ay^2$, where $a$ is an integer other than $1$. If so, are there any references ?