Created
October 15, 2015 20:05
-
-
Save rcabreu/8564cf6ced899a56d0ef to your computer and use it in GitHub Desktop.
Sieve of Erathostenes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vi primes; | |
bool prime[1000100]; | |
void generatePrimes(int n) { | |
for (int i = 2; i * i <= n; i++) | |
if (prime[i]) | |
for (int j = i * i; j <= n; j += i) | |
prime[j] = false; | |
int cnt = 0; | |
for (int i = 2; i <= n; i++) | |
if (prime[i]) | |
primes.pb(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment