Non unique factorization in $\mathbb{Z}_5$ 
Prove $3X^3+4X^2+3=(X+2)^2(3X+2)=(X+2)(X+4)(3X+1)$ in $\mathbb{Z}_5$.

I see that $2$ is a root (since $-24+16+3=-5$) , then $3X^3+4X^2+3=(X+2)(3X^2)$, and also $-4$ (since -$64\cdot3+16\cdot4+3=-125$) and although $x=-1/3$ is not in $\mathbb{Z}_5$, because it also works as a root then $3x+1$ is a nother factor. 
Then it should be $3X^3+4X^2+3=(X+2)(X+4)(3X+1)$ but the product of the right side gives $3X^3+24X^2+30X+8=3X^3+4X^2+3+5(4X^2+6X^2+1)=3X^3+4X^2+3.$
But why is it $3X^3+4X^2+3=(X+2)^2(3X+2)$? It seems $(X+2)^2(3X+2)=(X^2+2X+4)(3X+2)=3X^4+8X^2+10X+8=3X^4+3X^2+3+5(X+2X+1)=3X^4+3X^2+3$ which is not the initial polynomial.
Also, $\mathbb{Z}_5$ is UFC domain, wouldn't the double factorization imply a contradiction?
 A: No contradiction.

In a UFD (such as $\mathbb{Z}_5[x]$), the factorization is unique, only up to unit factors.

Note that $2$ and $3$ are units in $\mathbb{Z}_5$, hence are also units in $\mathbb{Z}_5[x]$.

Also, we have $6=1$.

Then since
$$x+4 = 6x+4 = 2(3x+2)$$
and
$$3x+1 = 3x + 6 = 3(x+2)$$
the factors match up, one-to-one, up to unit factors. 

Another way to see it is as follows . . .
\begin{align*}
&(x+2)(x+4)(3x+1)\\[4pt]
=\;&(x+2)(x+4)(3x+1)(6)&&\text{[since $6=1$]}\\[4pt]
=\;&(x+2)\bigl(3(x+4)\bigr)\bigl(2(3x+1)\bigr)\\[4pt]
=\;&(x+2)(3x+12)(6x+2)\\[4pt]
=\;&(x+2)(3x+2)(x+2)&&\text{[since $12=2$ and $6=1$]}\\[4pt]
=\;&(x+2)^2(3x+2)\\[4pt]
\end{align*}
which shows how we can convert one of the factorizations directly into the other, by multiplying the original factors by selected unit factors whose product is $1$ (e.g., by $2$ and $3$).
A: Factorization is only unique up to associates; e.g. over the reals, we can factor $4x^2 - 1$ in many different ways
$$ 4x^2 - 1 = (2x-1)(2x+1) = 4\left(x - \frac{1}{2}\right)\left(x + \frac{1}{2}\right) = (4x-2)\left(x + \frac{1}{2} \right)$$
In $k[x]$, we most commonly normalize by factoring out an overall unit so as to make the nonconstant factors monic polynomials; the individual factors of this form are unique. (the ordering is not)
Doing so, you would further factor
$$ (X+2)^2 (3X+2) = 3 (X+2)^2 (X+4) $$
$$ (X+2)(X+4) (3X+1) = 3 (X+2)(X+4)(X+2) $$
and we can see that, in both cases, the factorizations really do have the same factors.
In other words, what you were overlooking was:


*

*$3X+2$ and $X+4$ are associates

*$3X+1$ and $X+2$ are associates

