Diophantine equation in a polynomial ring 
I have to calculate the inverse of the polynomial $(2x^2+x+1)$ in the quotient ring $\frac{Z_3[x]}{<x^3+2x+2>}$. 

My idea was that I could solve the following equation, but I have no idea where to begin:$$(x^3+2x+2)u+(2x^2+x+1)v = 1.$$
 A: Notice that $\ \ g\,\equiv\, x^3- x - 1,\ $ and $\, f\, \equiv\, -x^2 + x + 1,\ $ by $\ 3\equiv 0$
Hence $\,{\rm mod}\ g:\ \color{#a0f}x\,(\color{#0a0}{x^2\!-\!1})\equiv \color{#c00}{\bf 1}.\ $  Our first Euclid step $\,g,f\to g\!+\!xf = \color{#0a0}{x^2\!-\!1}\,$ is $\,\rm\color{#0a0}{lucky}.$ 
Thus $\ \color{#a0f}x\left[g\!+\!xf \equiv \color{#0a0}{x^2\!-\!1}\right]\ \ $  (i.e. scale this congruence by $\,\color{#a0f}x\,$ then use the above) 
$\ \ \Rightarrow\ x\,g\!+\!x^2f\equiv\color{#c00}{\bf 1}\ \Rightarrow\ x^2f\equiv 1 \pmod{\! g}\,\ $ so $\,\ f^{-1} \equiv x^2\,$ in $\, \Bbb Z_2[x]/(g)$

Remark $\ $  Above we saw that the first reduction $\, g+xf\, $ of the (extended) Euclidean algorithm yields an element $\,\color{#0a0}{x^2\!-\!1}$ with obvious inverse mod $\,g\,$ (being a factor of $\,g\!-\!1).\,$ This is a common optimization when computing inverses.
Just as for integers, the (extended Euclidean algorithm) works in any domain with a (constructive) Euclidean algorithm (i.e. division with remainder), such as $\,F[x]\,$ for $\,F$ a (constructive) field, i.e. we have the implications Euclidean $\Rightarrow$ Bezout $\Rightarrow$ PID (ignoring constructive concerns).
A: For the given ring we have $x^3+2x+2 \equiv 0$ (same as $x^3 \equiv x+1$), so in general all you need is to find $ax^2+bx+c$ in the ring such that 
\begin{align*}
(ax^2+bx+c)(2x^2+x+1) & \equiv 1
\end{align*}
Multiplying these polynomials and using the congruence condition $x^3 \equiv x+1$ and $x^4 \equiv x^2+x$ should yield the result.
If all goes well, then you should have $a=1,b=0,c=0$. Thus the inverse is $x^2$.
A: Hint:
The general method, for any base field, is to use the Extended Euclidean algorithm to obtain a Bézout's relation:
$$u(x)(2x^2+x+1)+v(x)(x^3+2x+2)=1.$$
The the inverse of $2x^2+x+1$ modulo $x^3+2x+2$ is simply $v(x)$.
Here is a layout. Note that $2x^2+x+1=-x^2+x+1$, so, to simplify the computations we'll apply the algorithm to $x^3+2x+2=x^3-x-1$ and $x^2-x-1$:
$$\begin{array}{rccl}
r(x)&u(x)&v(x)&q(x)\\
\hline
x^3-x-1&0&1\\
x^2-x-1&1&0& x+1\\
\hline
x&-x-1&1&x-1\\
-1&x^2&-x+1\\
\hline
\end{array}$$
Thus we have $\;-1=x^2(x^2-x-1)+(-x+1)(x^3-x-1)$, or
$$1=x^2(2x^2+x+1)-+(x-1)(x^3+2x+2),$$
and the inverse of $2x^2+x+1$ is $x^2 $.
