here is my code
not able to think any other method to remove TLE
TLE error shown
@HemantNasa,
You are supposed to use the prime seive optimisation technique. Also make sure that you call the primeseive function that you will make before the test cases only to prevent TLE.
Precompute the prime numbers using sieve technique.
In the sieve technique where you create a boolean array of 1000005 size.
And start from the first prime number i.e. 2. Take its square(4) and increment it by the number you took (i.e. 4,6,8,10 and so on). Mark all these as false since they cannot be primes.
Now take the next unmarked number, 3. And mark 9,12,15 and so as false. Similarly do it for 4. 16,20,24 and so on as false.
When you finish the loop, count the number of primes within the range.
Now your approach is correct. Its just that you are calling this for every input. Don’t do that. Just get all prime numbers within the range (pre compute) and then just simple iterate through the prime numbers array to get your answer.
Thanks… now its solved… Thank you very much