Fix prime factorization algorithm