returns the prime numbers num the prime numbers are calculated using an odd sieve implementation of the sieve of eratosthenes algorithm see for reference https en wikipedia orgwikisieveoferatosthenes oddsieve2 oddsieve3 2 oddsieve10 2 3 5 7 oddsieve20 2 3 5 7 11 13 17 19 odd sieve for numbers in range 3 num 1 returns the prime numbers num the prime numbers are calculated using an odd sieve implementation of the sieve of eratosthenes algorithm see for reference https en wikipedia org wiki sieve_of_eratosthenes odd_sieve 2 odd_sieve 3 2 odd_sieve 10 2 3 5 7 odd_sieve 20 2 3 5 7 11 13 17 19 odd sieve for numbers in range 3 num 1
from itertools import compress, repeat
from math import ceil, sqrt


def odd_sieve(num: int) -> list[int]:
    

    if num <= 2:
        return []
    if num == 3:
        return [2]

    
    sieve = bytearray(b"\x01") * ((num >> 1) - 1)

    for i in range(3, int(sqrt(num)) + 1, 2):
        if sieve[(i >> 1) - 1]:
            i_squared = i**2
            sieve[(i_squared >> 1) - 1 :: i] = repeat(
                0, ceil((num - i_squared) / (i << 1))
            )

    return [2] + list(compress(range(3, num, 2), sieve))


if __name__ == "__main__":
    import doctest

    doctest.testmod()