Prime visits(tle error)


why my code time limit error

Hey @suhailrashidsalma its giving TLE because your code complexity is O(Range*Queries) which is not fast enough. So instead of solving each query in O(Range) time , you need to solve it in O(1) time.
You can do this by using a dp array which stores the number of primes up until that index ,i.e, dp[i] should store the number of primes from 2 to i. Using this dp array you can answer each query as dp[b]-dp[a].

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.