Prime visits check the mistake

#include
using namespace std;
#define ll long long
void prime_sieve(int *p)
{
for(int i=3;i<=1000000;i+=2)
{
p[i]=1;
}

for(int i=3;i<=1000000;i+=2)
{
	if(p[i]==1)
	{
		for(ll j=i*i;j<=1000000;j++)
		{
			p[j]=0;
		}
	}
}
p[2]=1;
p[1]=p[0]=0;

}
int main() {

int p[1000000]={0};
prime_sieve(p);

int csum[1000000]={0};

for(int i=1;i<1000000;i++)
{
	csum[i]=csum[i-1]+p[i];
}

int q;
cin>>q;

while(q--)
{
	int a,b;
	cin>>a>>b;

	cout<<csum[b]-csum[a-1]<<endl;
}
return 0;

}

@arsh_goyal Please change your prime_sieve function to this

void prime_sieve(int* p){
for(ll i=3;i<=1000000;i+=2){
p[i]=1;
}
for(ll i=3;i<=1000000;i+=2){
if(p[i]){
for(ll j=i*i;j<=1000000;j+=i){
p[j]=0;
}
}
}
p[2]=1;
}

and increase size of your p[] to p[1000005]

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.