Here's a easy solution


#1

vector Solution::sieve(int A) {
bool v[A+1];
memset(v, false, sizeof(v));
int n=A;
vector ans;
for(int i=2;i<sqrt(n);i++)
{
for(int j=i*i;j<n;j=j+i)
{
v[j]=true;
}
}
for(int i=2;i<n;i++)
{
if(v[i]!=true)
ans.push_back(i);
}
return ans;
}