<s>[INST] Find the remainder when $f(x)$ divided by $(x^2 + x + 1)(x+1)$. When a polynomial $f(x)$ is divided by $x^2 + x + 1$ and $(x+1)^2$, the remainder are $x+5$ and $x-1$ respectively. Find the remainder when $f(x)$ is divided by $(x^2 + x + 1)(x+1)$.
First, I let the remainder be $Ax^2 + Bx +C$, then I try to find the values of $A$, $B$ and $C$. There is $3$ unknowns so we need three equations but I can only get two equations. 
 [/INST] $$p(x)\equiv (x-1)\pmod{(x+1)^2} $$
implies $p(x)\equiv (x-1) \equiv -2 \pmod{(x+1)}$. We know that $p(x)\equiv(x+5)\pmod{x^2+x+1}$, or
$$ p(x) = (x+5) + (x^2+x+1) r(x) $$
hence
$$ p(x) \equiv 4 + r(x)\pmod{(x+1)}$$
and $r(x)\equiv -6\pmod{(x+1)}$. It follows that
$$ p(x) = (x+5)+(x^2+x+1)(-6+(x+1)s(x)) $$
and
$$ p(x)\equiv \color{red}{(x+5)-6(x^2+x+1)} \pmod{(x+1)(x^2+x+1)}.$$
</s>