Optimized and fixed P3LargestPrimeFactor