Getting runtime error for the below code


#1

Comment body goes hevector Solution::sieve(int A) {
vectorprimes;
vectorans;
for(int i=0;i<=A;i++)
primes[i]=1;

primes[0]=0;
primes[1]=0;

for(int i=2;i<=sqrt(A);i++)
{
    if(primes[i]==true)
    {
        for(int j=2;i*j<=A;j++)
        primes[i*j]=0;
    }
}
for(int i=2;i<=A;i++)
{
    if(primes[i]==true)
    ans.push_back(i);
}
return ans;

}
re.


#2

Looks like you have declared primes as vector, so you need to add elements with push_back or declare primes as primes(A+1, 0)…it declares and initializes.