I really don t know why I m having the segmentation fault. I m trying to generate primes with the code below:
#include <bits/stdc++.h>
using namespace std;
vector<int> prime_list;
void generate_primes(int upper_limit){
vector<bool> bool_index (upper_limit, true);
for(int i = 2; i<upper_limit; i++){
if (bool_index[i]){
::prime_list.push_back(i);
for(int j = i*i; j<upper_limit; j+=i){
bool_index[j] = false;
}
}
}
}
int main(){
generate_primes(300000); //for big numbers it gives a segmentation fault
for(int i: prime_list){
cout<<i<<" ";
}
return 0;*/
}
任何解决办法?