import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int noOfCountries = cin.nextInt();
while(noOfCountries-->0){
long firstCountry = cin.nextLong();
long secondCountry = cin.nextLong();
int primeCountries=0;
for(long i=firstCountry;i<=secondCountry;i++){
if(isPrime(i)){
++primeCountries;
}
}
System.out.println(primeCountries);
}
}
public static boolean isPrime(long country){
if(country<=1)return false;
if( country == 2 || country == 3) return true;
if( country %2 ==0 || country %3 == 0)return false;
for(long i=3;i<Math.sqrt(country);i++){
if(country%i==0){
return false;
}
}
return true;
}
}
I don’t know why but my code fails for test case 2 and 3.
I know this has to be solved using sieve of eratosthenes but I just wanted to know the above code is falling.