This is not difficult, just do long division x^3 expression divide
by the x^2 expression. The remainder (x+_) term will be one of the
factor already.
The modified question is not difficult, it is just a bit more
fun.
Using your earlier method, it will not be possible to solve the
modified question.
Your suggestion of using the long division method to solve the
modified question
also has the problem of not being able to divide due to the
existence of a and b.
Mikethm has already shown the correct method to solve the
modified question
ie the modified question can be solved by using the method used
by Mikethm to
solve the original question.