Improves common prime factorization function in C++