Skip to content

Instantly share code, notes, and snippets.

@jkrempus
Created May 28, 2012 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jkrempus/2817289 to your computer and use it in GitHub Desktop.
Save jkrempus/2817289 to your computer and use it in GitHub Desktop.
prime sieve on odd numbers
void oddSieve(bool[] isPrime) // index i of isPrime corresponds to 2 * i + 1
{
isPrime[] = true;
isPrime[0] = false;
auto n = isPrime.length * 2 + 1;
for(int i = 3; i * i <= n; i += 2)
if(isPrime[i/2])
for(int j = (i + i + i) / 2; j < n/2; j += i)
isPrime[j] = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment