Incorrect output

The code has passed only 1 of the test cases
#include
#define ll long long
using namespace std;
void prime(ll n,ll *p,ll csum)
{
p[0]=p[1]=0;
p[2]=1;
for(ll i=3;i<=n;i=i+2)
p[i]=1;
for(ll i=3;i<=n;i=i+2)
{
if(p[i]==1)
{
for(ll j=i
i;j<=n;j=j+i)
p[j]=0;
}
}
csum[0]=p[0];
for(ll i=1;i<=n;i++)
{
csum[i]=csum[i-1]+p[i];
}
}
int main() {
ll n,a,b;
cin>>n;
ll N=1000000,p[N+1]={0},csum[N+1]={0};
prime(N,p,csum);
while(n–)
{
cin>>a>>b;
cout<<csum[b]-csum[a-1]<<endl;
}
return 0;
}

please paste the code at ide.codingblocks.com and share

1 Like

Unfortunately, you did something wrong and the code is not there.

Paste your code there, and click save. Then share the link.

Don’t declare large arrays inside a function.

problem sorted, thanks!

1 Like