Hello guys,
I tried GQR problem and got TLE (as I expected). Here’s a link to my submission.
I am guessing I am getting TLE due to extra log(n) factor in calculating gcd. I read the editorial but couldn’t get it fully. It would be great if someone can help me in understanding that.
Also, is there a way I could improve my solution or is it that I need to change my implementation as per editorial? I mean to ask that if there are any optimizations possible in my solution.

Let A[X] is divisible by D, and Y is a position for the previous number(Y<X and A[Y] is divisible by D) for all numbers X and D, so if L <= Y < X <= R then answer is at least D. Think about it.