Test case 2 not fulfilled output is correct

Optimize your code using sieve. Your code isn’t time optimized

can you plz help how can i optimize it using seive. i have not done it before.

sieve is used to get all the prime numbers in a certain range in n log log n time. It uses the concept that we iteratively cross out all the multiples of primes from our entire range and what’s left are the prime numbers. Sieve comes in handy for questions where we need primes in a certain range mostly 10^6 and calculating them on demand is time-consuming. For more detailed tutorial on Sieve of Eratosthenes, refer to the GFG article: https://www.geeksforgeeks.org/sieve-of-eratosthenes/

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.