Prime number generation optimizations