Prime Visits TLE in TestCase 1 and Wrong Ans In TestCase2

Sir in this question we have to use prime sieve ?? Plz Check My code and help me if there is any errors thank you …
Code :-#include
using namespace std;

bool isPrime(int n){
if(n==1){
return false;
}
for(int j=2;j*j<=n;j++){
if(n%j==0){
return false;
}
}
return true;
}

int main(){

int t;
cin>>t;

while(t--){
 int a,b;

cin>>a>>b;
int cnt=0;
for(int i=a;i<=b;i++){
    if(isPrime(i)){
        cnt+=1;
    }
}
cout<<cnt<<endl;
}
return 0;

}

@koliswaroop93 hello swaroop ,
please share your code using coding blocks ide

you are getting tle because your solution time complexity is high roughly O(t*max(a,b)*sqrt(max(a,b)))
hint to make it efficient
a) try using sieve of erathothanes
b) precalculate the count of primes
i hope you find this helpful
regards
Aman