I'm gettin' SIGABRT runtime error on my code. Could someone tell me what can be problem? Thanks.
/* Prime Generator */
#include <iostream>
#include <vector>
using namespace std;
int *list = NULL;
void sieve(long p){
list[0] = 0;
for(int i = 2; i * i < p; i++){
if(list[i-1] == 1){
for(int j = i+i; j <= p; j += i){
list[j-1] = 0;
}
}
}
}
int main(){
int t;
vector<long> v;
long m,n;
cin >> t;
for(int i = 0; i < t; i++){
cin >> m >> n;
list = new int[n];
for(int i = 0; i < n; i++)
list[i] = 1;
sieve(n);
for(long j = m; j <= n; j++){
if(list[j-1] == 1)
v.push_back(j);
}
v.push_back(-1);
delete [] list;
list = NULL;
}
for(int i = 0; i < v.size(); i++){
if(v.at(i) == -1)
cout << endl;
else
cout << v.at(i) << endl;
}
return 0;
}
created
last reply
- 2
replies
- 290
views
- 2
users