Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

sieve of eratosthenes c++

int n;
vector<char> is_prime(n+1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
    if (is_prime[i] && (long long)i * i <= n) {
        for (int j = i * i; j <= n; j += i)
            is_prime[j] = false;
    }
}
Source by cp-algorithms.com #
 
PREVIOUS NEXT
Tagged: #sieve #eratosthenes
ADD COMMENT
Topic
Name
4+3 =