Let
$r(B)$ be the number of integers $1 \leq n \leq B$ such that $n = x^2 + y^2$ for some $x, y \in \mathbb{Z}.$  

Then it is a known theorem of Landau that
$$
r(B) \sim C \frac{B}{\sqrt{\log B}}
$$
for some $C > 0$. I was wondering if there is a generalization of this result for
slightly more general function $ax^2 + b y^2$ where $a, b$ are positive integers.
Thank you!



A generalisation of theorem of Landau on sum of two squares?
The general result you seek is due to Paul Bernays, who studied under E. Landau in Göttingen and proved in his dissertation (1912) that $$\tag{$\star$}\sum\_{n \le x} b\_Q(n) \sim C\_Q \frac{x}{\sqrt{\log x}}$$
as $x \to \infty$ where $Q(x,y)=ax^2+bxy+cy^2$ is a primitive positive-definite binary quadratic form ($b^2−4ac<0$, $a>0$, $a,b,c \in \mathbb{Z}$) and $b\_Q$ is the indicator function of integers representable as $Q(x,y)$ ($x,y \in \mathbb{Z}$). The constant $C\_Q$ depends only on the discriminant of $Q$.


You want to apply it with $b=0$ (in the above notation); if $a,b$ (in your notation) are not coprime you need to first reduce to the primitive case before applying Bernays’ result.
(E.g. if $Q\_1$ and $Q\_2$ are two binary quadratic form with the same discriminant, it does not necessarily follow that $\sum\_{n \le x} b\_{Q\_1}(n) \sim \sum\_{n \le x} b\_{Q\_2}(n)$ unless you first assume $Q\_i$ are primitive.)


The dissertation is titled “Über die Darstellung von positiven, ganzen Zahlen durch die primitiven, binären quadratischen Formen einer nicht-quadratischen Diskriminante”, and is available [here](https://eudml.org/doc/203258).


Since the dissertation is in German, let me mention that there are two alternative proofs, giving rate of decay for the error term in $(\star)$.


R. W. K. Odoni in “On norms of integers in a full module of an algebraic number field and the distribution of values of binary integral quadratic forms” (Mathematika, Lond. 22, 108–111 (1975)) proved that $(\star)$ holds with a relative saving of $(\log x)^{c\_Q}$ for some $c\_Q>0$.


O. M. Fomenko, in “Distribution of values of Fourier coefficients for modular forms of weight 1” (J. Math. Sci., New York 89, No. 1, 1051–1071 (1998)) gave a third proof, that leads to formulas for $C\_Q$ and $c\_Q$. See section 2 of this paper for a useful overview of other results.


