$\DeclareMathOperator\gcd{gcd}$Take $q\in \mathbb N$ and $X>0$ ($q$ not necessarily smaller than $X$). A sum such as
$$\sum\_{d\leq X}(q,d)$$
is easily seen to be $\ll q^\epsilon (X+q)$ so that the gcd doesn't make the sum much larger than how it would be without it — the values for which $(q,d)$ are significant are rare.


If I have instead a sum like
$$\sum\_{dd'\leq X}(q,d+d')$$
can I still conclude a similar bound, thinking that the $d+d'$ should give just as "random values" to $(q,d+d')$ as did $d$ to $(q,d)$? Or is this completely the wrong way to think about it?


It's of course similar to asking about
$$\sum\_{\substack{dd'\leq X\\q\mid d+d'}}1$$
which seems easy enough but I'm still a bit unsure… is this even $\ll (qX)^\epsilon (X/q+1)$?



Gcd of linear function
**1.** We have
$$\sum\_{\substack{dd'\leq X\\q\mid d+d'\\d\leq d'}}1
=\sum\_{d\leq\sqrt{X}}\sum\_{\substack{d'\leq X/d\\q\mid d+d'\\d\leq d'}}1
\leq\sum\_{d\leq\sqrt{X}}\sum\_{\substack{c\leq 2X/d\\q\mid c}}1
\leq\sum\_{d\leq\sqrt{X}}\frac{2X}{qd}<\frac{2X(1+\log\sqrt{X})}{q}.$$
We get the same bound when the roles of $d$ and $d'$ are interchanged,
hence in the end
$$\sum\_{\substack{dd'\leq X\\q\mid d+d'}}1<\frac{2X(2+\log X)}{q}\ll\_\epsilon\frac{X^{1+\epsilon}}{q}.$$


**2.** From the last inequality we infer
$$\sum\_{dd'\leq X}(q,d+d')\leq
\sum\_{r\mid q}r\sum\_{\substack{dd'\leq X\\r\mid d+d'}}1
\ll\_\epsilon\sum\_{r\mid q}r\frac{X^{1+\epsilon}}{r}\ll\_\epsilon (qX)^\epsilon X.$$


