Prime visit|| code is showing TLE in one test case|| plz check

import java.util.*;
public class Main {
static Scanner sc=new Scanner (System.in);
public static void main(String args[]) {
int N=sc.nextInt();
while(N>0){
int a=sc.nextInt();
int b=sc.nextInt();
N–;
int flag=0,count=0;
for(int i=a;i<=b;i++){
if(i==0||i==1||(i%2==0&&i!=2)){
continue;
}
flag=1;
for (int j = 2; j <= i / 2; ++j) {
if (i % j == 0) {
flag = 0;
break;
}
}
if(flag==1){
count++;
}
}
System.out.println(count);
}
}
}

@Rajput.apry hi,
read about sieve of eratosthenes .it is one of the efficient methods of computing primes, you will be good to go!