Non-trivial upper bound for a sum related to $p^{-1}z \pmod q$ and $q^{-1}z \pmod p$

Let $$p, q$$ be two distinct prime number. I'm trying to provide a non-trivial upper bound for the sum $$S(p, q) = \sum_{1 \leq x < p} \sum_{1 \leq y < q} \frac{1}{\|x / p\| \, \|y / q\| \, \|x/p + y/q\|},$$ where $$\|t\|$$ denotes the distance of $$t \in \mathbb{R}$$ from the nearest integer.

Precisely, I'm interested in having $$S(p, q) = o((pq)^2)$$ as $$p, q$$ go to infinity in some way.

I know that $$\min(p, q) \to +\infty$$ doesn't suffices, since $$S(p, q) \geq (pq)^2 / (q - p)$$ (considering $$x = 1$$ and $$y = q - 1$$), and we can take a sequence of primes $$p_k < q_k$$ such that $$p_k \to +\infty$$ and $$q_k - p_k$$ is bounded.

Maybe $$S(p, q) = o((pq)^2)$$ as $$p \to +\infty$$ and $$q/p \to +\infty$$ ?

The motivation comes from the fact that $$\sum_{\substack{1 \leq z < pq \\ (pq, z) = 1}} \frac1{|p^{-1}z \bmod q|\,|q^{-1}z \bmod p| \, z} = \frac{S(p, q)}{(pq)^2} ,$$ where $$|p^{-1}z \bmod q| = \min\{|r| : r \in \mathbb{Z}, pr \equiv z \pmod q\}$$, and similarly for $$|q^{-1}z \bmod p|$$. Therefore, $$S(p, q) = o((pq)^2)$$ means that, on average, $$|p^{-1}z \bmod q|$$, $$|q^{-1}z \bmod p|$$, and $$z$$ cannot be all small.

Thanks for any help

• I'm fairly certain that one can obtain the bound $$S(p,q) \ll \frac{(pq)^2}{p+q}(\log p)(\log q).$$ If I have the time, I'll write up an answer to show this. Note that this is essentially sharp, since the term with $x=y=1$ is $$\frac{(pq)^2}{p+q}.$$ Dec 26, 2021 at 0:05

If you just want $$o()$$, the story is rather simple. Let $$a_{xy}$$ be the remainder of $$qx+py\mod pq$$ where all remainders modulo $$P$$ are assumed to be between $$-P/2$$ and $$P/2$$. Note that all $$a_{xy}$$ are distinct, so if we have any set $$Z$$ of pairs $$(x,y)$$, then $$\sum_{(x,y)\in Z}\frac 1{a_{xy}}\le 2(1+\log|Z|)$$. What we want to show is just $$\sum_{0<|x| Now for $$k=0,1,2\dots$$ consider $$Z_k=\{(x,y): 2^k\le |xy|<2^{k+1}\}$$ and note that $$|Z_k|\le C(k+1)2^{k}$$. Thus the sum over $$Z_k$$ is at most $$2^{-k}(1+\log|Z_k|)\le C(k+1)2^{-k}$$ regardless of $$p,q$$. Thus the only danger is that the sum over $$Z_k$$ for some fixed $$k$$ does not tend to $$0$$, i.e., that there exists $$C>0$$ such that $$ap+bq+c=0$$ for some $$a,b,c$$ with $$0<|a|+|b|+|c| along a subsequence of pairs $$(p,q)$$ you are considering (in which case the corresponding term alone gives a positive constant). If you eliminate this possibility in any way ($$q/p\to+\infty$$ is more than enough), then you are in good shape.
This is not mean to be a full answer, but one which illustrates how one can prove an estimate like the one in my comment through a rather brute force'' approach.
To illustrate the idea of the computation, let's deal with the case when $$p=2$$ and $$q$$ is some odd prime number, so $$S(2,q) = \sum_{1 \leq y < q} \frac{1}{\frac{1}{2} \left|\left| \frac{y}{q}\right|\right| \cdot \left|\left| \frac{1}{2} + \frac{y}{q}\right|\right|}.$$ Note that the expression inside the second $$||\cdot||$$ symbol in the denominator is always in $$(\frac{1}{2},\frac{3}{2})$$, and therefore $$\left|\left| \frac{1}{2} + \frac{y}{q}\right|\right| = \begin{cases} \frac{1}{2} - \frac{y}{q} & \text{if \frac{1}{2} + \frac{y}{q} < 1}, \\ \frac{y}{q} - \frac{1}{2} & \text{if \frac{1}{2} + \frac{y}{q} > 1}. \end{cases}$$ This motivates us to decompose $$S(2,q)$$ as $$S(2,q) = 2 \Big(\sum_{1\leq y \leq \frac{q-1}{2}} + \sum_{\frac{q+1}{2}\leq y < q} \Big)\frac{1}{ \left|\left| \frac{y}{q}\right|\right| \cdot \left|\left| \frac{1}{2} + \frac{y}{q}\right|\right|} = 2(T_1 + T_2),$$ say. In each sum, the $$||\cdot||$$ expressions can be evaluated explicitly, and we obtain \begin{aligned} T_1 &= \sum_{1\leq y \leq \frac{q-1}{2}} \frac{1}{\frac{y}{q} \left(\frac{1}{2} - \frac{y}{q} \right)} = q^2 \sum_{1\leq y \leq \frac{q-1}{2}} \frac{1}{y\left(\frac{q}{2}-y \right)}, \\ T_2 &= \sum_{\frac{q+1}{2}\leq y < q} \frac{1}{\left(1-\frac{y}{q} \right) \left(\frac{y}{q} -\frac{1}{2} \right)} = q^2 \sum_{\frac{q+1}{2}\leq y < q} \frac{1}{(q-y)\left(y-\frac{q}{2}\right)}. \end{aligned} Note that in each of the expressions in the denominators on the right, exactly one of the two factors is larger than $$\frac{q}{4}$$ (to see this, just split the sums depending as $$y\leq \frac{q}{4}$$ and $$y\leq \frac{3q}{4}$$, respectively). Omitting a few details of the calculations, we have $$S(2,q) \ll q \sum_{1\leq y \leq \frac{q}{4}} \frac{1}{y} \ll q\log q.$$ There's some technicalities about changing variables in the second sum and what the exact limits of summation work out to be, but the above inequality is morally correct.
• For the general case $p > 2$, the computation gets really messy