Tle in last test case help

NEED HELP IN LOGIC HOW TO AVOID TLE IN THIS CODE EVEN THOUGH THE METHORD I HAVE USED I M GETTING TLE

You have to do this question using Optimized Prime Sieve.Without this, it will give TLE. A lecture video on Prime Sieve must be there in the number theory section of your course. Refer that first and then proceed with the problem.
If even after using Prime sieve you get a TLE then refer this: Prateek loves Candy

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.