Skip to content

Instantly share code, notes, and snippets.

@rcabreu
Created October 15, 2015 20:05
Show Gist options
  • Save rcabreu/8564cf6ced899a56d0ef to your computer and use it in GitHub Desktop.
Save rcabreu/8564cf6ced899a56d0ef to your computer and use it in GitHub Desktop.
Sieve of Erathostenes
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