# Determine $a$ values allowing $x^2+ax+2$ to be divided by $x-3$ in $\mathbb Z_5$

Determine for which $a$ values $f = x^2+ax+2$ can be divided by $g= x-3$ in $\mathbb Z_5$.

I don't know if there are more effective (and certainly right) ways to solve this problem, I assume there definitely are, but as I am not aware of them, I thought I could proceed like this: I have divided $f$ by $g$, pretending $a$ to be a constant in $\mathbb Q$, the resulting quotient is $x+(a+3)$, the reminder is $2+3(a+3)$. In order to have an exact division it needs to happen:

\begin{aligned} 2+3(a+3) = 0 \end{aligned} \begin{aligned} 2+3a + 4 = 0 \end{aligned} \begin{aligned} 3a + 1 = 0 \Rightarrow 3a=-1 \Rightarrow 3a = 4 \Rightarrow a= \frac{4}{3}=3 \end{aligned}

now I would expect $x^2+3x+2 = (x+1)(x-3)$, but it isn't the case because $(x+1)(x-3) = x^2-2x-3$. Is my way to solve this exercise totally wrong and it would be better if I'd set my notebook on fire (and in this case please feel free to jump in) or I am just doing some calculation wrong?

-

$x-a$ is the factor of polynimial $f(x)$ iff $f(a)=0\implies (x-3)$ divides $f(x)=x^2+ax+2$ iff $f(3)=11+3a\equiv 0\pmod 5\implies 3a\equiv-11\pmod 5\implies 9\pmod 5\implies a\equiv3\pmod 5$. In your solution you are getting $(x+1)(x-3)=x^2-2x-3\equiv x^2+3x+2\pmod 5$ as $-2\equiv 3\pmod 5$ and $-3\equiv 2\pmod 5$. so your solution is fine.
Recall that $x-c$ divides $P(x)$ iff $P(c)=0$. Use the version of that appropriate for $\mathbb{Z}_5$. That is faster than polynomial division for polynomials of higher degree.
Remark: Your calculation is correct. Your belief that it is wrong is wrong, and reflects unfamiliarity with finite fields. For $-2\equiv 3\pmod{5}$ and $-3\equiv 2\pmod{5}$. Thus in $\mathbb{Z_5}$, we have $-2=3$ and $-3=2$. So the polynomial $x^2-2x-3$, viewed as a polynomial over $\mathbb{Z}_5$, is the same as the polynomial $x^2+3x+2$.