Not getting AC for CHFHEIST

Here is my code:
https://www.codechef.com/viewsolution/47834875

I’m only getting partially accepted.

Because you’re supposed to do it without a loop. TLE means time limit exceeded.

even O(n) isn’t fast enough for this?

As given time limit is 0.5 seconds therefore a loop of 10^6 will not pass

Well, yeah it’s linear time but you need to look at which variable it depends on. Your loop is O(D).

ah ok, thanks!

you got TLE because we can do it in O(1) by using formula of sum of A.P