Please explaim me sir that why I can not able to summits this question prime visits

PMO gives two random numbers a & b to the Prime Minister. PM Modi wants to visit all countries between a and b (inclusive) , However due to shortage of time he can’t visit each and every country , So PM Modi decides to visit only those countries,for which country number has two divisors. So your task is to find number of countries Mr. Modi will visit.

Input Format
The first line contains N , no of test cases. The next N lines contain two integers a and b denoting the range of country numbers.

Constraints
a<=1000000 & b<=1000000.
N<=1000

Output Format
Output contains N lines each containing an answer for the test case.

Sample Input

2

1

10

11

20

Sample Output

4

4

Explanation
PM Modi chooses countries with numbers 2,3,5 and 7 for the first testcase.
For the second testcase , he chooses countries with numbers 11,13,17 and 19.

import java.util.*;

public class Main {

public static void main(String args[]) {

	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();

	while(n>0){

		int a = sc.nextInt();

		int b = sc.nextInt();

		for(int i = a ; i <= b ; i++){
			int divisor = 2;
			 boolean flag = true ;
			 while(divisor <=  a - 1){
				 if ( a % divisor == 0){
					 flag = false;

				 }
				 divisor = divisor + 1 ;
				 
			 }
			 if(flag == true){
				 flag = false ;
				 System.out.println(i);
			 }
		}
		n--;
	}


}

}

@abhisheksinghchauhan442,
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.

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.