Can someone tell me what's wrong with my code? I got this error: runtime error (SIGXFSZ). I have checked many test cases and for all of them my program was well written.
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <math.h>
#define MAX 1000000000
#define RANGE 100000
using namespace std;
bool mark[10000];
void simpleSieve(int limit, vector<int> &prime)
{
bool mark[limit + 1];
memset(mark, true, sizeof(mark));
for (int p = 2; p * p < limit; p++)
{
if (mark[p] == true)
{
for (int i = p * 2; i < limit; i += p)
mark[i] = false;
}
}
for (int p = 2; p < limit; p++)
{
if (mark[p] == true)
{
prime.push_back(p);
}
}
}
void segmentedSieve(int a, int b, vector<int> &primes)
{
int limit = floor(sqrt(MAX)) + 1;
for (int i = 0; i <= primes.size(); i++)
{
if (primes[i] >= a && primes[i] <= b)
printf("%d\n", primes[i]);
if (primes[i] > b)
break;
}
int low = limit;
int high = limit + 10000;
if (high > b)
high = b;
while (low < b)
{
memset(mark, true, sizeof(mark));
for (int i = 0; i < primes.size(); i++)
{
int loLim = floor(low / primes[i]) * primes[i];
if (loLim < low)
loLim += primes[i];
for (int j = loLim; j < high; j += primes[i])
mark[j - low] = false;
}
for (int i = low; i < high; i++)
if (mark[i - low] == true)
printf("%d\n", i);
low = low + 10000;
high = high + 10000;
if (high >= b)
high = b;
}
}
int main() {
int t, a, b;
scanf("%d", &t);
vector<int> primes;
simpleSieve(floor(sqrt(MAX)) + 1, primes);
for (int i = 1; i <= t; i++)
{
scanf("%d%d", &a, &b);
segmentedSieve(a, b, primes);
if (i != t)
printf("\n");
}
return 0;
}