$ By the polynomial remainder theorem, $P(3) = 5$ and $P(-1) = 2$. Then solve the two equations simultaneously to find the values for $a$ and $b$.
No need for polynomial long division, the remainder theorem already accounts for that, so it makes the calculations easier to compute.