Skip to content

Instantly share code, notes, and snippets.

@balamark
Created April 21, 2015 03:55
Show Gist options
  • Save balamark/eb1236630d6e311cd4f8 to your computer and use it in GitHub Desktop.
Save balamark/eb1236630d6e311cd4f8 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes
void gen_primes() {
int i,j;
for(i=0;i<MAX;i++) primes[i] = 1;
for(i=2;i<=(int)sqrt(MAX);i++)
if (primes[i])
for(j=i;j*i<MAX;j++) primes[i*j] = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment