What I would call the "factor theorem", for polynomials, is:
"Polynomial P(x) has x- a as factor if and only if P(a)= 0".
Here \(\displaystyle P(x)= x^3 + 3x^2 - 18x -40\). Further, the "rational root theorem" tells us that any rational number making P equal to 0 must be an integer that evenly divides 40. Those are 1, -1, 2, -2, 4, -4, 5, -5, 8, -8, 10, -10, 20, -20, 40, and -40.
It is easy to see, by evaluating, that P(-2)= -8+ 12+ 36- 40= 48- 48= 0 so x-(-2)= x+ 2 is a factor.
Dividing P(x) by x+ 2 gives P(x= (x+ 2)(x^2+ x- 20)= (x+ 2)(x- 4)(x+ 5).