Additional optimizations for prime generation.