Prime visits two test cases wrong

showing two test cases wrong please tell error in my program

import java.util.Scanner;
import java.lang.Math;
public class prime_visits {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int N = s.nextInt();

int count=1;

while(count<=N)
{
	long a = s.nextLong();
	long b = s.nextLong();
	long num = a, prime = 0;
	while (num <= b) {
		boolean flag = false;
		for (int i = 1; i <= (int)Math.sqrt(num); i++) {
			if (num % i == 0 && i != 1) {
				flag = true; 
				
			}

		}
		if (flag == false &&num!=1)
			prime++;
		num++;
	}
	count++;
  System.out.println(prime);
}

}
}

in your code it is showing wrong ans because you are considering 0 as a prime numberā€¦consider the input 0 10ā€¦
handle this corner caseā€¦moreover in one test case your code is showing tleā€¦to optimize this use seive of eratosthenes to pre compute prime numberse(according to the constraints) and then loop over the reange[a,b] to count the prime numbersā€¦

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.