if (x-a) is a factor of x^3-a^2x+x+2 then 'a' is equal to

x^3-a^2x+x+2 is divisible by x-a

so x=a has to give a result of 0 when subbed in

a^3 - a^2 (a) + a + 2 = 0
a^3 - a^3 + a + 2 = 0

a = -2