So i was solving my homework, and i did this piece of code which is supposed to find the biggest difference beetween two prime numbers in the interval of [a,b], and i got "Process returned -1073741819 (0xC0000005)"
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
bitset <10000000>v;
int main()
{
for (int i = 2; i < 10000000; i++)
{
if (v[i] == 0)
{
for (int j = i * i; j < 10000000; j += i)
v[j] = 1;
}
}
int n, a, b, maxi = 0, mini = 0, smax = 0;
cin >> a >> b;
int poz = a;
while (v[poz] == 1)
poz++;
int prev = poz;
poz++;
while (v[poz] == 1 && poz < b)
poz++;
if (poz == b && v[b] == 1)
{
cout << -1; return 0;
}
int next = poz;
poz++;
while (poz <= b)
{
if (next - prev > smax)
{
smax = next - prev;
maxi = next;
mini = prev;
}
if (v[poz] == 0)
{
prev = next;
next = poz;
}
poz++;
}
cout << mini << " " << maxi;
return 0;
}
i expected 43 with 47