Prime Visits Problem

1 out of 3 test cases is showing Run error.

#include<iostream>
#define ll long long int
using namespace std;

int prime_visits(int sieve[], int a, int b){
	for(int i=3; i<=b; i+=2){
		sieve[i] = 1;
	}

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

	int cnt = 0;
	for(int i=a; i<=b; i++){
		if(sieve[i] == 1){
			cnt++;
		}
	}
	return cnt;
}


int main() {

	int t;
	cin>>t;
	while(t--){
		int a,b;
        cin>>a>>b;
		int sieve[1000005]{0};
		cout<<prime_visits(sieve,a,b)<<endl;

	}

	return 0;
}

i think you passed all testcase now

any further doubt

No.
For the code that i’ve shared, one test case is failing.

Make i as long long int also

Modified Code

yes all test cases passed now

But why do we need to declare i as long long int?
In the loop, i<=b, and b<=10^6, so why we needed to do that?

because ii will be integer if i is integer
so make i ll so that i
i will also be ll and don’t overflow

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.