Let $f(x,y) = a^2 x^2 - (b^2 - 2ac)xy + c^2 y^2$ be a positive definite binary quadratic form with co-prime integer coefficients such that $b \ne 0$. For a given pair of integers $(u,v)$ and a prime $p | f(u,v)$, we see that $u$ is a quadratic residue modulo $p$ if and only if $v$ is because


$$\displaystyle b^2 uv \equiv (ax + cy)^2 \pmod{p}.$$


Define the function $r(u,v)$ by


$$\displaystyle r(u,v) = \sum\_{m | f(u,v)} \left(\frac{u}{m} \right) = \sum\_{m | f(u,v)} \left(\frac{v}{m}\right).$$


Here $\left(\frac{\cdot}{n}\right)$ denotes the Jacobi symbol. What is the asymptotic value of 


$$\displaystyle \sum\_{f(u,v) \leq X} r(u,v)?$$



Averaging the Jacobi symbol over an ellipse
I will work with $f=u^2+v^2$ and the region $|u|,|v|\leq X$
but the argument easily generalises. The numbers $m$ go up to $X^2$ but by Dirichlet's divisor trick we can assume that they go up to $\sqrt{X^2}$.
Then the congruence $u^2+v^2\equiv 0 \mod{m}$ can be written equivalently as $u\equiv \alpha v \mod{m}$ for some $\alpha \mod{m}$ that satisfies $\alpha^2+1\equiv 0 \mod{m}$. Then the contribution of these $m$ is  

$$
\sum\_{1\leq m \ll X}
\sum\_{\substack{\alpha \mod{m}\\\alpha^2+1\equiv 0 \mod{m}}} \left(\frac{\alpha}{m}\right)
\sum\_{\substack{|u|,|v|\leq X\\ u\equiv \alpha v \mod{m}}}1
.$$ The sum over $u,v$ is really the number of integer planar points in a lattice, therefore it equals $c\_0 X^2m^{-1}+O(X|\mathbf{y}|^{-1}+1)$,
where $\mathbf{y}$ comes from the first successive minima and it is of size $\ll \sqrt{m}$ by Minkowski's theorem. The main term gives $$X^2 \sum\_{m\ll X}\frac{1}{m}\sum\_{\substack{\alpha \mod{m}\\\alpha^2+1\equiv 0 \mod{m}}} \left(\frac{\alpha}{m}\right)$$ which are the first terms in a convergent series coming from some $L$-function without a pole at $1$.The $O(1)$ term gives $\ll X^{1+\epsilon}$ because the sum over $\alpha$ is of course $\ll m^\epsilon$, although a bound of the form $\ll \tau(m)^A$ for some fixed $A>1$ can also be proved (and needed when $f$ has larger degree). The most interesting idea of Daniel comes from how to handle the sum over $\mathbf{y}$. He showed that while $\mathbf{y}\ll \sqrt{m}$, it is possible to show that on average over $m$ the vector $\mathbf{y}$ that depends on both $m,\alpha$ attains its maximum value $\sqrt{m}$, thus providing a crucial saving in the error term (crucial when the degree of $f$ is higher). Here is how: note that $\mathbf{y}=(y\_1,y\_2)$ belongs to the lattice hence $m$ divides $y\_1^2+y\_2^2$. Thus the contribution is $$\ll X \sum\_{|\mathbf{y}|\ll \sqrt{X}} \frac{1}{|\mathbf{y}|}\sum\_{d|y\_1^2+y\_2^2}1\ll X^{1+\epsilon}\sum\_{|\mathbf{y}|\ll \sqrt{X}} \frac{1}{|\mathbf{y}|}\ll X^{3/2+\epsilon}.$$ Dealing with higher degrees forces to separately consider the contribution of $m$ lying extremely close to $\sqrt{x^{\deg(f)}}$, say $m \in (\sqrt{X^{\deg(f)}} (\log X)^{-100},\sqrt{X^{\deg(f)}}]$. These will go into the final error term and for this one needs a more complicated approach related to the distribution of divisors in small intervals. It was a surprise when the paper of Daniel came out because people believed one could not go higher than $\deg(f)\leq 3$ which was done by Greaves in a very long paper. It would be interesting to see if the approach of Daniel works for weighted projective cases, for example $$\sum\_{1\leq u,v \leq X} \sum\_{d|u^2+v^4}1,$$ this has not been done previously.


