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);
}
}
}