I am getting error in one of the testcases

int k=2;
//cin>>k;
int a[100]={1,10,11,20};
int i=0;
//for(int j=0;j<k;j++)
//{
// cout<<“Enter the limits:”;
// cin>>a[i];
// i++;
// cin>>a[i];
// i++;
//}

//for(int i=0;i<k*2;i++)
//{
// cout<<a[i]<<" ";
//}

for(int i=0;i<k*2;i=i+2)
{
int sum=0;
for(int j=a[i];j<=a[i+1];j++)
{
// cout<<“j:”<<j<" ";
int i;
bool isPrime = true;
if(j<=1)
isPrime=false;
else
{
for(i = 2; i <= j / 2; ++i)
{
if(j % i == 0)
{
isPrime = false;
break;
}
}
}
if (isPrime)
sum++; }

cout<<sum<<" ";

}

Use code pair for sharing code. It would be easier for me to understand.

Well you are using a root n approach. Which will surely give a Time limit exceed. Use seive for precomputing and then answer in 0(1) per query.

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.