TLE for jmagum

My solution passed the first test case but showed TLE for 2nd sub test case.But I have already calculated prime factors for all numbers initially.

Link to ans:https://www.codechef.com/viewsolution/15586772

in each query you are calculating the cumulative again and again from l to r… better precompute your ans for every query from 0 to i… and then just print ans[r]-ans[l-1]…
and also in your first loop… i should go from 2 to MAX… not sqrt(MAX)… as there can be some prime integers between sqrt(MAX) and M which you didn’t considered in your answer.

1 Like

Thankx.It was a great help!!

Dont forget to mark answers as accepted once the issue is resolved.

1 Like