Sha256: b604fe9f480042a40d41b14ee2540d593ec81c7df033dbd3cef783089933f426
Contents?: true
Size: 493 Bytes
Versions: 396
Compression:
Stored size: 493 Bytes
Contents
#include "sieve.h" #include <algorithm> #include <list> #include <numeric> namespace sieve { std::vector<int> primes(int n) { std::vector<int> result; std::list<int> candidates(n-1); std::iota(candidates.begin(), candidates.end(), 2); while (!candidates.empty()) { const int next = candidates.front(); candidates.pop_front(); result.push_back(next); candidates.remove_if([next](int n) { return n % next == 0; }); } return result; } }
Version data entries
396 entries across 396 versions & 1 rubygems