How can I get polynomial $p(x)$? $p(x)$ is divided evenly into $x^{2}+1$, and $p(x)+1$ is divided evenly into $x^{3}+x^{2}+1$. How can I get $p(x)$?

The given data tells us:
$$\begin{align}r(x)(x^2 + 1) &= p(x)\\
s(x)(x^3 + x^2 + 1) &= p(x) + 1
\end{align}$$
The above equations imply that
$$s(x)(x^3 + x^2 + 1) - r(x)(x^2 + 1) = 1. \tag1$$
Does the structure of the equation ring any bells? Yes! Bezout's identity!
Now use Euclid's division algorithm on $x^2 + 1$ and $x^3 + x^2 + 1$ to obtain:
$$x(x^3 + x^2 + 1) - (x^2 + x - 1)(x^2 + 1) = 1\tag2$$
Compare (1) and (2) and eventually get $p(x)$.
