\(P\left(x\right)=\left(x-2\right)Q\left(x\right)+1\) \(\Rightarrow P\left(2\right)=1\)
\(P\left(x\right)=\left(x+1\right).R\left(x\right)+2\Rightarrow P\left(-1\right)=2\)
\(P\left(x\right)=\left(x^2-x-2\right)\left(2x-1\right)+ax+b\) (1)
Thay \(x=2\) vào (1): \(P\left(2\right)=2a+b\Rightarrow2a+b=1\)
Thay \(x=-1\) vào (1): \(P\left(-1\right)=-a+b\Rightarrow-a+b=2\)
\(\Rightarrow\left\{{}\begin{matrix}2a+b=1\\-a+b=2\end{matrix}\right.\) \(\Rightarrow\left\{{}\begin{matrix}a=-\frac{1}{3}\\b=\frac{5}{3}\end{matrix}\right.\)
\(\Rightarrow P\left(x\right)=\left(x^2-x-2\right)\left(2x-1\right)-\frac{1}{3}x+\frac{5}{3}\)