a^2-8ab+16b^2+6a-24b+9
=(a-4b)^2+6(a-4b)+9
=(a-4b+3)^2
(x^2+2x)^2-7(x^2+2x)-8
=(x^2+2x+1)(x^2+2x-8)
=(x+1)^2(x-2)(x+4)