number_theory/eratosthenes.cpp
/*
    Implementation of the sieve of Eratosthenes.

    Arguments:
        - primes: Array that wiT be turned into list of primes/divisors.
        - n: Upper bound of sieve.
*/
Implementation of the sieve of Eratosthenes.
Arguments:
primes: Array that wiT be turned into list of primes/divisors.
n: Upper bound of sieve.
Implementation of the sieve of Eratosthenes . Arguments : primes : Array that wiT be turned into list of primes / divisors . n : Upper bound of sieve .
void eratosthenes(vector<T>& primes, T n) {
    primes.resize(n + 1); iota(begin(primes), end(primes), 0);
    for (size_t i = 2; i * i <= n; i++) {
        if (primes[i] == i) {
            for (size_t j = i + i; j <= n; j += i) primes[j] = i;
        }
    }
}
void eratosthenes ( vector < T > & primes , T n ) { primes . resize ( n + 1 ) ; iota ( begin ( primes ) , end ( primes ) , 0 ) ; for ( size_t i = 2 ; i * i <= n ; i ++ ) { if ( primes [ i ] == i ) { for ( size_t j = i + i ; j <= n ; j += i ) primes [ j ] = i ; } } }
Implementation of the sieve of Eratosthenes.
Implementation of the sieve of Eratosthenes .