Editorial says Let's fix one x and try to solve this task for it.
okay makes our time complexity q*(something), moving on...
How to find number of i that ai mod x ≤ m for some m
We can use binary search of some sort, making our complexity
q*log(x)*checkerForM, how in the world is this complexity not TLE
Can anyone explain it to me.
read the complete tutorial.
So, the idea is to precompute answer for all x. For each x, we found answer in $$$O(\frac{n}{x}\cdot log(n))$$$ and in sum it will be $$$O(n\cdot log^2(x))$$$. So, we can answer querry in constant time.
Why does this simple code implementing your approach giving TLE
btw Pa_sha orz
why does it matter, logx or logx*logx should be almost equal, why TLE in my case ?