Time limit exceed in 1 test case

can you tell me the logic to write an efficient code for this problem
my code is-
#include
using namespace std;
bool checkprime(int num)
{
int i;
for(i=2;i<num;i++)
{
if(num%i==0)
{
return false;
}
}
return true;
}
int main() {
int t;
cin>>t;
while(t>0)
{
long long int a,b;
cin>>a>>b;
int i,j,count=0;
for(i=a;i<=b;i++)
{
if(i==1)
{
continue;
}
if(checkprime(i))
{
count++;
}
}
cout<<count<<endl;
t–;
}

return 0;

}

Hi @pragyachoudhary1111, in this question try reducing the bounds of your for loop in checkprime function. Also in this question you should take the help of sieve of eratosthenes.