SPOJ Problem-PRIME1 giving runtime error (SIGSEGV) why?

Problem Link: http://www.spoj.com/problems/PRIME1/

Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>

using namespace std;

#define M 100000

bool marked[M];

vector <int> primes;

void seive(int r1, int r2)
{
    for(int i=2; i<=r2; i++)
    {
        if(marked[i]==false && i>=r1)
        {
           primes.push_back(i);
        }
        for(int j=i+i; j<=r2; j+=i)
        {
            marked[j]=true;
        }

    }
}

int main()
{
    int t,r1,r2;
    cin>>t;

    while(t--)
    {
        cin>>r1>>r2;
        seive(r1,r2);

        vector<int>::iterator it = primes.begin();
        while ( it != primes.end())
            cout << *it++ <<endl;

        primes.clear();

    }

    return 0;
}


Why this solution giving runtime error (SIGSEGV)??
http://www.cplusplus.com/forum/general/112111/
I understand that you don't have access to the testcases used by the server, however you should create your own.
Try the limits of the problem, try corner cases, try random cases.


You have an invalid access in the array `marked'.
Your algorithm would visit the numbers from 2 to `r2', `marked' may only hold 100000 elements, however the input can be a lot bigger than that.
Topic archived. No new replies allowed.