Failing test case 0

failing test case 0 due to timelimit, pls correct my code

#include
using namespace std;
int main() {
int n;
cin>>n;
while(n–)
{
int a,b;
cin>>a>>b;
int cnt=0;
int i,j;
for(i=a;i<=b;i++)
{

		for(j=2;j<=i-1;j++)
		{
			if(i%j==0)
			{
				break;
			}

		}
		if(j==i)
		{
			cnt++;
		}
	}
	cout<<cnt<<endl;
}
return 0;

}

@shahnawaz hey ,you are using brute force methos to find prime numbers between a and b thats why it is giving TLE due to its high complexity .Use Sieve of eratosthenes which will find prime numbers in less compexity.
Hope you get it,try this it will get submitted.
Happy coding :blush:

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.