Preview:
vector<int> sieve(int n){
    int size = sqrt(n);
    bool primes[size+1];
    memset(primes,true,size+1);
    primes[0] = primes[1] = false;
    for(int i = 2; i <= size; i++){
        if(primes[i]){
            int k = 2;
            while(i*k <= size){
                primes[i*k] = false;
                k++;
            }
        }
    }
    vector<int> ans;
    for(int i = 0 ; i<= size; i++)
        if(primes[i])
            ans.push_back(i);
    return ans;

}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter