I am getting run time error SIGFPE in question MAIN111 - Strictly not a Prime.
My solution is
#include<bits/stdc++.h>
using namespace std;
#define MAX 100001
typedef long long int ll;
typedef unsigned long long int ull;
void sieve(vector < ll > &prime){
bool check[MAX];
memset(check, true, sizeof(check));
check[0]=false;
check[1]=false;
for(ll i=2;ii<MAX;i++){
if(check[i]){
prime.push_back(i);
for(ll j=ii;j<MAX;j+=i)
check[j]=false;
}
}
}
//Prime numbers in given range
//Time complexity is same as normal sieve O(nlog(logn)) but space complexity is O(sqrt(n))
ll segmentedSieve(ll l, ll r){
ll limit=floor(sqrt®)+1;
vector < ll > prime;
sieve(prime);
ll n=r-l+1;
bool primeSegment[n+1];
memset(primeSegment,true,sizeof(primeSegment));
for(ll i=0;prime[i]*prime[i]<=r;i++){
ll cp=prime[i];
ll base=floor(l/prime[i])*prime[i];
if(base<l){
base+=prime[i];
}
for(ll j=base;j<=r;j+=prime[i]){
primeSegment[j-l]=false;
}
if(base==cp){
primeSegment[base-l]=true;
}
}
ll sum=0;
for(ll i=l;i<=r;i++){
if(primeSegment[i-l])
sum++;
}
return sum;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t–){
ll a,b;
cin>>a>>b;
if(a>b)
swap(a,b);
cout<<(b-a-(segmentedSieve(a,b))+1)<<endl;
}
return 0;
}