Improved prime number generation