optimized listPrime algorithm