Hi. I’ve used Cummulative array for calculating count of number of primes but still facing TLE
You can view my code here:
Hi. I’ve used Cummulative array for calculating count of number of primes but still facing TLE
You can view my code here:
For each test case you are calling the prime sieve again and again.
Call the prime sieve only once,outside the loop for test cases to prepare the all the primes and then check.
Another small optimization can be done replacing line 14 with for(ll j = i*i;j<=n;j+=2*i)
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.