### SIGABRT error cause for this program

What is the casuse of SIGABRT error in this program
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182`` ``````#include #include #include #include using namespace std; bitset<100000> mybits; /* Function print_primes(int x, int y) - prints all the prime nos. between range [x,y]. */ void print_primes(int a, int b, vector primes) { if (b <= primes[primes.size() - 1]) { // numbers are already precalculated just print them. for (int i = 0; i < primes.size(); i++) { if (primes[i] >= a && primes[i] <= b) cout << primes[i] << endl; } return; } // use segmented sieve. mybits.reset(); int limit = (int) sqrt(b); int temp; for (int i = a; i <= b; i++) { if (mybits[i] == 1) goto end; for (int j = 0; primes[j] <= limit; j++) { if (i % primes[j] == 0) { mybits.set(i - a); temp = i - a + primes[j]; while (1) { if (temp > b - a) goto end; mybits.set(temp); temp = temp + primes[j]; } } } end: ; } for (int i = 0; i <= b - a; i++) if (!mybits.test(i)) cout << i + a << endl; } int main() { /* Calculate all the primes upto sqrt(10^9) i.e, 31623 using precomputation */ vector primes; primes.push_back(2); primes.push_back(3); int n, a, b; for (int i = 5; i < 31623; i = i + 2) { for (int j = 2; j <= sqrt(i); j++) { if (i % j == 0) { goto end; } } primes.push_back(i); end: ; } cin >> n; for (int i = 0; i < n; i++) { cin >> a; cin >> b; print_primes(a, b, primes); cout << endl; } return 0; } ``````

Sample Input
1
500000 600000
 ```terminate called after throwing an instance of 'std::out_of_range' what(): bitset::set 39: mybits.set(temp);```

temp = 100000
Last edited on
If I'm correct it means that I am trying to set a bit position that is out of range right!!!
yes.
Topic archived. No new replies allowed.