Skip to content

Latest commit

 

History

History
15 lines (13 loc) · 236 Bytes

File metadata and controls

15 lines (13 loc) · 236 Bytes

##Sieve of Eratosthenes

Find all the prime numbers <= n.

vector<int> isPrime(n+1, 1);
for (int i=2; i*i<=n; i++) {
    if (!isPrime[i])
        continue;
    for (int j=i*i; j<=n; j+=i) {
        isPrime[j] = 0;
    }
}