Why test case 2 is not running. I saw from the video and the discussion forums also

#include
using namespace std;
void PrimeNum(long long int p,long long int b){
for( long long int val1=2 ;val1<=b;val1++){
p[val1]=1;
}
for(long long int val1=2;val1<=b;val1++){
if(p[val1]){
for( long long int val2=2
val1;val2<=b;val2+=val1){

            p[val2]=0;
        }
    }
}
p[2]=1;
p[1]=p[0]=0;
return;

}
int main()
{
long long int val4;
cin>>val4;
for( long long int val3=0;val3<val4;val3++){
long long int a,b;
cin>>a>>b;
long long int count=0;
long long int*p=new long long int [1000001];
PrimeNum(p,b);
for(long long int i=a;i<=b;i++)
{
if(p[i]==1)
{
count++;
}
}
cout<<count<<endl;
}
return 0;
}

Hey @kalindiyadav5
why are you doing code in c++. you are enrolled in java course ???
try to write code in java
here’s my suggestion to you. While doing these kinds of questions try to minimize the redundant operations.

Here it is calculating primes.
Think if T is like 10^4 and n is 10^6 and in worst case each of the test cases has very large value so you will be computing primes again and again and that will give you a TLE.

So precompute the primes once upto the given constraints, you will be good to go

1 Like

Thank you. Actually i have the C++ course too thus i tried doing this in C++. As i looked for solutions i found in c++. But i will submit the code in java only. I just wanted to see how it happens in c++.
thank you.

@kalindiyadav5
done this question ??

Working on it. Thanks.