Need help with Prime visits (TLE case #3)
#include
#include<math.h>
using namespace std;
int main() {
int n;
cin>>n;
while(nā){
int a,b,c=0;
cin>>a>>b;
if(a<2)a=2;
for(int i=a;i<=b;i++){
int temp=0;
int k=sqrt(i)+1;
for(int j=2;j<=k&&j<i;j++)
if(!(i%j)){temp=1;break;}
if(!temp)c++;
}
cout<<c<<endl;
}
}
TLE in Prime visits
#include
#include<math.h>
using namespace std;
int main() {
int n;
cin>>n;
while(nā){
int a,b,c=0;
cin>>a>>b;
if(a<2)a=2;
for(int i=a;i<=b;i++){
int temp=0;
int k=sqrt(i)+1;
for(int j=2;j<=k&&j<i;j++)
if(!(i%j)){temp=1;break;}
if(!temp)c++;
}
cout<<c<<endl;
}
}
Hey @Equinoxx9, first of all sorry for this late reply. Check constraint for your code they are of small range, given question has high constraints. Replace these int to long long int