https://ide.codingblocks.com/s/52051
sending a link help me to get error!!!
This question can be done easily using the sieve. You can pre-compute the primes for the given range and store them, the you can simply answer the given number of test cases by traversing those stored values.
The approach you have used runs a loop for each test case again again, thus increasing the time complexity of the code. Try to optimize using the above mentioned approach.
This code will give TLE (Time Limit Exceeded) error because in your code the loop runs separately for each test case to calculate number of prime numbers in given range. So the total iterations exceed 10^8 in worst case, according to the given constraints. Hence it gives TLE.
More optimized approach is to pre compute the prime numbers in the range given in question and then traverse that array for each test case.
I would recommend you to go through videos of Time and Space Complexity given in the course!!!