GCDMAT2 - GCD OF MATRIX (hard)
You have given a matrix of size nxm. Every cell of matrix denote gcd of respective indices. For ex-
A 3x2 matrix have entries
You have given queries i1 j1 i2 j2.
You have to find the sum of matrix formed by upper left corner (i1,j1) and lower right corner (i2,j2).
First line indicates number of testcases. (T<=50000)
Next line have space separated two integer n and m. (1<=n,m<=1000000).
Next T lines contains queries i1 j1 i2 j2.
where i1<=i2 j1<=j2.
Print ans modulo M for each query in newline. (M=10^9+7)
Input: 2 3 2 1 1 2 2 2 1 3 2 Output: 5 5
Is O(T*sqrt(n)) really okay? I have no idea how to make it faster.
This problem requires heaviest constant-optimization among all problems I've ever done in recent 3 months.
Something better than O(T*sqrt(n)) is required ?