Problem in solving prime visit problem. below is my code written .out of 3, 2 test cases are running and in 1 test case wrong answer error is coming

#include<bits/stdc++.h>
using namespace std;

int main() {
long long i,j,n,v,r,s;
long long a[1000005]{0};
for(i=3;i<1000005;i+=2)
a[i]=1;
for(i=3;i<1000005;i+=2)
{
if(a[i]==1)
{
for(j=i*i;j<1000005;j=j+i)
a[j]=0;
}
}
a[0]=a[1]=0;a[2]=1;

for(i=1;i<1000005;i++){
a[i]=a[i]+a[i-1];

}

long long t;
cin>>t;
while(t–){
cin>>r>>s;
if(s>r)
v=a[s]-a[r-1];
else
v=a[r]-a[s-1];
cout<<v<<endl;
}
return 0;
}

this is my code.out of 3, 2 test cases are running and in 1 test case wrong answer error is coming.

Hello @pradyumna_gupta please wait i am checking your code.

Hello @pradyumna_gupta this is the corrected code:


if you have any doubt you can ask here:
Happy Learning!!

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.