#include using namespace std; template void printC(Container& c) { for (auto i: c) { cout << i << " "; } cout << endl; }; int main(void) { auto sieve = [](int n) { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. vector primes(n + 1, true); for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a prime if (primes[p] == true) { // Update all multiples of p greater than or // equal to the square of it numbers which are // multiple of p and are less than p^2 are // already been marked. for (int i = p * p; i <= n; i += p) primes[i] = false; } } // Print all prime numbers cout << "primes to " << n << ": "; for (size_t i = 2; i < primes.size(); i++) if (primes.at(i)) cout << i << " "; cout << endl; }; sieve(17); return 0; }