My code is unable to clear test case 2 due to TLE. Can you make improvements to this code? Or do we have to dedicatedly use arrays only?
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int tc = scn.nextInt();
while(tc-->0){
int n = scn.nextInt();
int m = scn.nextInt();
int count = 0;
for(int i = n;i<=m;i++){
for(int p = 2;p<=i;p++){
if(i%p==0){
if(p!=i){
break;
}
else{
count++;
}
}
}
}
System.out.println(count);
}
}
}