I need to factorize $f=8x^3+x^2+2x+6 \in \mathbb Z_{13}[x]$. I figure I can divide $f$ by $(x-a)$ and then determine for which $a$ value the reminder is equal to $0$.
So the resulting quotient is $8x^2+(8a+1)x+(3+8a)$ and the reminder is $6+a(3+8a)$. As previously said I have to find a suitable $a$ value solution to $\begin{align} 6+a(3+8a)\equiv_{13}0 \Leftrightarrow a(3+8a)\equiv_{13}7\end{align}$
at this point I have to manually substitute the $a$ to $0,1,2,\,...$ and verify for every value which among them satisfies the equation. My question is for a small number like $13$ it is acceptable to run tests and see, but what if instead of $13$ there was $31$, is there any way that lets me spot that value without embarking in a pretty time consuming quest?
Edit: I'm not in the math field, but I have to take the exam, maybe this question is going beyond the contents of my class, so I was wondering if there is any resonably simple answer to that.