for (x+1) and (x+2) be a factor of given polynomialp(x) , they must be its roots. and
hence according to remainder theorem p(-1) and p(-2) must be 0,
so p(-1)=-1-a+b-8=0
p(-2)=-8-4a+2b-8=0
solving these 2 simentanous equation.
b-a=9
b-2a=8
so b= 10 and a is 1
and polynomial becomes x^3-x^2-10x-8=0
since product of roots is 8(-d/a) and 2 roots are -1 and -2 last root must be 4 so factor is (x-4)
you could also go for long division.!!!
cheers