optimization of prime generation