Sieve of Eratosthenes method: While I use code 1 to filter prime numbers I get a segmentation fault for an input 16777214, whereas in code 2 it doesn't give a segmentation fault. The segmentation fault comes due to the first 2 lines of code 1 where I define (bool prime) and (memset). What could be the reason I get this fault on https://www.interviewbit.com/problems/prime-sum/
//code 1:
vector<int> Solution::primesum(int A){
bool prime[A+1];
memset(prime, true, sizeof(prime));
for (int p=2;p<=sqrt(A);p++){
if(prime[p] == true){
for (int i=p*p;i<=A;i+=p)
prime[i] = false;
}
}
}
````
````
//code 2:
vector<int> Solution::primesum(int A){
vector<bool> prime(A+1);
for(int i=2;i<=sqrt(A);i++){
if(prime[i]==false){
for(int j=i*i;j<=A;j+=i)
prime[j] = true;
}
}
}
````
````