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?