Finding the remainder of a polynomial divided by $x^4+x^2+1$ if remainders when dividing by $x^2+x+1$, $x^2-x+1$ are $-x+1$, $3x+5$. 
Find the remainder of $f$ divided by $g(x)=x^4+x^2+1$ if the remainder of $f$ divided by $h_1 (x)=x^2+x+1$ is $-x+1$ and the remainder of $f$ divided by $h_2(x)=x^2-x+1$ is $3x+5$.

My attempt was to write $f(x)=(x^4+x^2+1)q(x)+Ax^3+Bx^2+Cx+D=(x^2+x+1)(x^2-x+1)q(x)+Ax^3+Bx^2+Cx+D$ and then factor out $x^2+x+1$ to get $f(x)=(x^2+x+1)[(x^2-x+1)q(x)+B]+Ax^3+(C-B)x+(D-B)$, then do the same for $x^2-x+1$ and then use that along with the known remainder of $f$ divided by $x^2+x+1$ and $x^2-x+1$ to obtain $A$, $B$, $C$, $D$. However, $Ax^3$ is in the way so I don't know how to proceed nor do I have any other ideas to start with.
 A: Using the Extended Euclidean Algorithm as described in this answer and adapted to polynomials yields
$$
\begin{array}{r|r|r|r}
\bbox[5px,border:2px solid #C00]{x^2+x+1}&\bbox[5px,border:2px solid #C00]{1}&0\\
\bbox[5px,border:2px solid #090]{x^2-x+1}&0&\bbox[5px,border:2px solid #090]{1}\\
2x\phantom{{}+0}&1&-1&1\\
1&\bbox[5px,border:2px solid #C00]{-\frac12x+\frac12}&\bbox[5px,border:2px solid #090]{\frac12x+\frac12}&\frac12x-\frac12\\
0&x^2\phantom{\frac12}-x+\,1&-x^2\phantom{\frac12}-x-\,1&2x\phantom{{}+\frac12}
\end{array}\tag1
$$
which says that
$$
\overbrace{\color{#C00}{\left(x^2+x+1\right)\left(-\tfrac12x+\tfrac12\right)}}^{\large\frac12-\frac12x^3}+\overbrace{\color{#090}{\left(x^2-x+1\right)\left(\tfrac12x+\tfrac12\right)}}^{\large\frac12+\frac12x^3}=1\tag2
$$
Which, in turn says that
$$
\frac12-\frac12x^3\equiv\left\{\begin{array}{}
0&\bmod x^2+x+1\\
1&\bmod x^2-x+1
\end{array}\right.\tag3
$$
and
$$
\frac12+\frac12x^3\equiv\left\{\begin{array}{}
1&\bmod x^2+x+1\\
0&\bmod x^2-x+1
\end{array}\right.\tag4
$$
Therefore, the desired polynomial is
$$
\begin{align}
\scriptsize(-x+1)\overbrace{\left(\tfrac12+\tfrac12x^3\right)}^{\substack{1\bmod x^2+x+1\\0\bmod x^2-x+1}}+(3x+5)\overbrace{\left(\tfrac12-\tfrac12x^3\right)}^{\substack{0\bmod x^2+x+1\\1\bmod x^2-x+1}}
&=3+x-2x^3-2x^4\\
&\equiv\bbox[5px,border:2px solid #CA0]{5+x+2x^2-2x^3}\bmod x^4+x^2+1\tag5
\end{align}
$$
A: This is where things go wrong:

My attempt was to write $f(x)=(x^4+x^2+1)q(x)+Ax^3+Bx^2+Cx+D=(x^2+x+1)(x^2-x+1)q(x)+Ax^3+Bx^2+Cx+D$ and then factor out $x^2+x+1$ to get $f(x)=(x^2+x+1)[(x^2-x+1)q(x)+B]+Ax^3+(C-B)x+(D-B)$

The remainder inside the brackets can have a linear term as well, so you should have written it as
$$
f(x) = (x^2 + x + 1)[(x^2 - x + 1)q(x) + Ax + (B-A)] + (C-B)x + (D-B+A).
$$
And similarly,
$$
f(x) = (x^2 - x + 1)[(x^2 - x + 1)q(x) + Ax + (B+A)] + (C+B)x + (D-B-A),
$$
at which point you can solve for all four coefficients.
A: Let the polynomial be $P(x)$. It is given that for some polynomials $Q(x),Q_1(x)$
$$P(x)=(x^2+x+1)Q(x)+1-x$$
$$P(x)=(x^2-x+1)Q_1(x)+3x+5$$
Now it is well known that $x^2+x+1$ has the zeros as $\omega,\omega^2$ and $x^2-x+1$ has the zeroes $-\omega,-\omega^2$, where $\omega=\frac{-1+i\sqrt{3}}{2}$
So We get
$$P(\omega)=1-\omega$$
$$P(\omega^2)=1-\omega^2$$
$$P(-\omega)=3\omega+5$$
$$P(-\omega^2)=-3\omega^2+5$$
Now let us assume for some polynomial $Q_2(x)$ we have
$$P(x)=(x^4+x^2+1)Q_2(x)+Ax^3+Bx^2+Cx+D$$
Using the fact that $x^4+x^2+1$ has the zeros $\omega,\omega^2,-\omega,-\omega^2$ we get four linear equations as:
$$\left[\begin{array}{cccc}
1 & \omega^{2} & \omega & 1 \\
1 & \omega & \omega^{2} & 1 \\
-1 & \omega^{2} & -\omega & 1 \\
-1 & \omega & -\omega^{2} & 1
\end{array}\right]\left[\begin{array}{c}
A \\
B \\
C \\
D
\end{array}\right]=\left[\begin{array}{c}
1-\omega \\
1-\omega^{2} \\
5-3 \omega \\
5-3 \omega^{2}
\end{array}\right]$$
Now let us solve by Cramer's rule. The determinant of the matrix is $\Delta =12$,
$\Delta_1=-24$, $\Delta_2=24$, $\Delta_3=12$ and $\Delta_4=60$.
Thus the values of $A,B,C,D$ are
$$\begin{aligned}
&A=\frac{\Delta_{1}}{\Delta}=-2 \\
&B=\frac{\Delta_{2}}{\Delta}=2 \\
&C=\frac{\Delta_{3}}{\Delta}=1 \\
&D=\frac{\Delta_{4}}{\Delta}=5
\end{aligned}$$
So the required remainder is
$$-2x^3+2x^2+x+5$$
A: Let $u=x^2+x+1,$ $v=x^2-x+1$ so that $uv=x^4+x^2+1.$  Let $P$ be the given polynomial.
$$P=uq_1-x+1\tag1$$
$$P=vq_2+3x+5\tag2$$
$$P=uvq_3+R\tag3$$
There are polynomials $\lambda$ and $\mu$ such that
$$\lambda u+\mu v=1\tag4$$
Suitable values are $\lambda={-x+1\over2}$  and $\mu= {x+1\over2} .$
By (1), (2) and (4),
$$P=\lambda uP+\mu vP=\lambda uvq_2+(3x+5)\lambda u+\mu uvq_1+(-x+1)\mu v$$
Therefore, modulo $uv,$ $R$ is
$$ (3x+5)\lambda u+(-x+1)\mu v\tag5  $$
Of course, we must reduce the degree in (5).
$$(3x+5)\lambda=(3x+5){-x+1\over2}={1\over2}(-5x+8-3v)\tag6$$
$$(-x+1)\mu=(-x+1){x+1\over2}={1\over2}(x+2-u)\tag7$$
By (5), (6) and (7),
$$R={1\over2}\big((-5x+8)(x^2+x+1)+(x+2)(x^2-x+1) \big)$$
$$= {1\over2}\big((-5x^3+3x^2+3x+8)+(x^3+x^2-x+2) \big)$$
$$\text{Thus,}\ \ \ R=-2x^3+2x^2+x+5. $$
A: Hint:
As the roots of $x^2+x+1=0$ are $w,w^2$ where $w$ is a complex cube root of unity,
the roots of $x^2-x+1=0$ are $-w,-w^2$
we can write $$f(x)$$
$$=p(x)(x^2+x+1)(x^2-x+1)+A(x-w)(x-w^2)(x+w)+B(x-w)(x-w^2)(x+w^2)+C(x-w^2)(x+w)(x+w^2)+D(x-w)(x+w)(x+w^2)$$
$$=p(x)(x^2+x+1)(x^2-x+1)+(x^2-x+1)(c(x-w^2)+d(x-w))+\cdots$$
$$-w+1=f(w)=(-2w)c(w-w^2)\implies2c=-w$$
Similarly, we can find $a,b,d$
