public
Created

prime sieve on odd numbers

  • Download Gist
oddSieve.d
D
1 2 3 4 5 6 7 8 9 10 11
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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.