Solved #47, optimized prime factorization