How to solve polynomial equations in factored form