Number of roots of polynomials in $\mathbb Z/p \mathbb Z [x]$

Hint $\ $ If $\,f\ne 0\,$ has $\,\ge n\,$ distinct roots $\,r_i$ then inductively applying the Factor Theorem (e.g. below) shows $\,f = c(x\!-\!r_1)\cdots (x\!-\!r_n),\,$ so $\ r\ne r_i\,\Rightarrow\, f(r)= c(r\!-\!r_1)\cdots (r\!-\!r_n) \ne 0\,$ since all factors $\ne 0,\,$ and $\,\Bbb Z_p\,$ is an integral domain. Thus $\,f\,$ has at most $\,n\,$ roots.

Aternatively, $\,f(r_i)= 0 \,\Rightarrow\, x-r_i \mid f(x).\,$ Being divisible by the nonassociate primes $\,x-r_i\,$ it follows $\,f\,$ is divisible by their lcm = product, so there are at most $\,\deg(f)\,$ factors ($\leftrightarrow$ roots)


Bifactor Theorem $\ $ Let $\rm\,a,b\in R,\,$ a commutative ring, and $\rm\:f\in R[x]\:$ a polynomial over $\,\rm R.\,$
If $\rm\ \color{#0a0}{a\!-\!b}\ $ is $\,\color{#c00}{\rm cancellable}\,$ in $\rm\,R\,$ (i.e. not a zero-divsor) $ $ then

$$\rm f(a) = 0 = f(b)\ \iff\ f\, =\, (x\!-\!a)(x\!-\!b)\ h\ \ for\ \ some\ \ h\in R[x]$$

Proof $\,\ (\Leftarrow)\,$ clear. $\ (\Rightarrow)\ $ Applying Factor Theorem twice, while canceling $\rm\: \color{#0a0}{a\!-\!b},$

$$\begin{eqnarray}\rm\:f(b)= 0 &\ \Rightarrow\ &\rm f(x)\, =\, (x\!-\!b)\,g(x)\ \ for\ \ some\ \ g\in R[x]\\ \rm f(a) = (\color{#0a0}{a\!-\!b})\,g(a) = 0 &\color{#c00}\Rightarrow&\rm g(a)\, =\, 0\,\ \Rightarrow\,\ g(x) \,=\, (x\!-\!a)\,h(x)\ \ for\ \ some\ \ h\in R[x]\\ &\Rightarrow&\rm f(x)\, =\, (x\!-\!b)\,g(x) \,=\, (x\!-\!b)(x\!-\!a)\,h(x)\end{eqnarray}$$

Remark $\ $ The theorem may fail when $\rm\ a\!-\!b\ $ is not cancelable (i.e. is a zero-divisor), e.g.

$$\rm mod\ 8\!:\,\ f(x)=x^2\!-1\,\Rightarrow\,f(3)\equiv 0\equiv f(1)\ \ but\ \ x^2\!-1\not\equiv (x\!-\!3)(x\!-\!1)\equiv x^2\!-4x+3$$