do tell me what is wrong in it. https://ide.codingblocks.com/s/122365
Primevisits (geting all the worng ans)
hi @vikashkmr519 ,
Here in the loop with index j you have done jj<=b whereas it should be jj<=i as we want to check all the j for a particular index i … Like in the case where i=5 you are going to check all the index till b . And then j=5 is valid because (5*5=25) which is less than b(100) .
this code in the ide is showing timelimit exceed for the 3 test case, please check it sir
That is because the algorithm you have used checks for each value in between a and b.There is a method to find primes and then store it in a boolean array. Method is known as Sieve of Eratosthenes.This method will reduce time taken .In the method make a boolean array of b+1 size and make all the fields as true and then run from 2 till sqrt(n) and if value at index i is true then do all the further multiple of i as false. Now use a second loop from a to search number of true in the array . This will give you your count in less time.
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.