Prateek Loves Candy

TIME LIMIT EXCEEDED ERROR

Hey @srishti200201_c9588863a697e1e7,
Since the input constraint is very large (10^6) and calculating the prime number over again is a costly process in terms of time. To optimise the solution we can store the prime numbers in beforehand. So, we need to use the Sieve of Eratosthenes to solve this question.

You can refer to this video to learn more https://youtu.be/yB57bcffJo4

Hope it helps :slight_smile:

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.