Time limit in case 0

import java.util.Scanner;

class PMO {

public static void main(String[] argS)
{
	Scanner input=new Scanner(System.in);
	int t=input.nextInt();
	int c=0;
	while(c<t) {
		int sum=0;
	int n1=input.nextInt();
	int n2=input.nextInt();
	int n,temp,i,a,b=0;
	while(n1<=n2) {
		n=n1;
		temp=n/2;
		for(i=2;i<=temp;i++) {
		 a=n%i;
		 if(a==0) b=1;
		}
		if(b==0&n!=1&n!=0) {
			sum=sum+1;
	}
		n1++;
		b=0;
	}
	 c++;
	 System.out.println(sum);
	}
}

}

Use Sieve of Eratosthenes to solve this problem. The method you are using has high time complexity

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.