If $f$ is a polynomial of degree $n$, then $f(x) \equiv 0\pmod p$ has at most $n$ solutions. I know that I have to prove this by induction on $n$ when we let $f(x)=a_{n}x^n + a_{n-1}x^{n-1} +\cdots + a_0$. I have two books in front of me with the complete proof but I don't see how after they assume that the theorem holds for a polynomial of degree $n-1$ and move on to show it holds for a polynomial of degree $n$ they say, 
Either $f(x) \equiv 0\pmod p$ has no solution or at least one solution. If it has no solution the theorem holds (How so? how come is it not also true in the second case?). 
Then they say, suppose that $r$ is a solution. That is $f(r) \equiv 0\pmod p$, and $r$ is a least residue $\pmod p$. Then because $x-r$ is a factor of $x^t -r^t$ for $t=0,1,2\ldots,n$, we have
$$\begin{align*}
f(x)\equiv f(x)-f(r) &\equiv a_{n}(x^n -r^n) + a_{n-1}(x^{n-1} -r^{n-1}) +\cdots + a_0(x -r)\pmod{p}\\
 &\equiv (x-r)g(x)\pmod p
\end{align*}$$
where $g$ is a polynomial of degree $n-1$. suppose that $s$ is also another solution of (1). Thus 
$$f(s) \equiv (s-r)g(s)\equiv0 \pmod p$$
because $p$ is prime it follows that 
$$s\equiv r\pmod p\text{ or }g(s) \equiv 0 \pmod p$$
from the inductions assumption, the second congruence has at most $n-1$ solutions. Since the first congruence has just one solution, the proof is complete.
I would just appreciate is someone could explain the reasoning behind this a little more. Thank you.
 A: The idea of the proof is simple. If $\,f(x) = (x\!-\!r)g(x)\,$ has $\,n\!+\!1 > \deg f\,$ roots then, as shown, the $\,n\,$ roots of $\,f\,$ different from $\,r\,$ are all roots of $\,g,\,$ so $\,g\,$ has $\,n > \deg g\, (= \deg(f)\!-\!1)\,$ roots, contra the induction hypothesis (see here for full details, and generalizations).
The proof essentially shows "additivity" of roots, i.e. $\,{\rm roots}(fg) = {\rm roots}(f) \cup {\rm roots}(g),\,$ which is true precisely because $\,\Bbb Z/p\,$ is a domain, i.e. $\, a,b\not\equiv 0\,\Rightarrow\,ab\not\equiv 0,\,$ i.e. no zero divisors exist (else it fails, e.g. $\!\bmod 8\!:\,  (x\!-\!1)(x\!+\!1)\,$ has root $\,x\equiv3\,$ which is neither a root of $\,x\!-\!1\,$ nor $\,x\!+\!1.$
More structurally: $\, a_i\ne a_j\in D\,$ a domain $\Rightarrow\ x-a_i\ $ are nonassociate primes in $\,D[x],\,$ since $\, D[x]/(x\!-\!a) \cong D\,$ is a domain. So $\,  x\!-\!a_1, \ldots, x\!-\!a_n\ |\ f(x) \Rightarrow  (x\!-\!a_1)\cdots (x\!-\!a_n)\ |\ f(x)\ $ by LCM = product for nonassociate primes.. Comparing degrees yields a contradiction if $\, n > \deg f.$
A: Another way of proving this that you might like better: Given a polynomial $f \in \mathbb Z[x]$ we can reduce its coefficients modulo $p$ to obtain an element $\bar f$ of $\mathbb F_p[x]$, where $\mathbb F_p = \mathbb Z/(p)$ is the field with $p$ elements. The result you now want to use is that a polynomial of degree $n \geq 0$ over a field has at most $n$ roots.
To prove that, use induction on $n$ and the division theorem as proved in these notes. To give more detail: if $f$ has a root $a$ then apply the division theorem to $f(x)$ and $x - a$.
[Note that you want to use the degree of the reduced polynomial. The integral polynomial $f(x) = p$, for example, has degree $0$, and yet it has $p$ zeros modulo $p$. Also note that it's important for $\mathbb F_p$ to be a field — the polynomial $2x$ has two roots in $\mathbb Z/(4)$, for example.]
A: Remember that you are trying to prove that the congruence $f(x)\equiv 0\pmod{p}$ has at most $n$ solutions. (Added. There must be an assumption that $a_n\not\equiv 0\pmod{p}$ missing, by the way)
The argument is essentially the same one we use to prove that a polynomial of degree $n$ has at most $n$ roots in any field: we do induction on the degree. 

If $f$ is of degree $0$, a nonzero constant, then it has no solutions and we are fine.
Assume the result holds for any polynomial of degree less than $n$, and that $f$ has degree $n\gt 0$. If $f$ has no roots, then we are done: $0$ is less than $n$, so $f$ satisfies the conclusion. If $f$ has at least one root $r$, then we can use the Factor Theorem to write $f(x) = (x-r) g(x)$ for some polynomial $g$ of degree $n-1\lt n$. If $s$ is a root of $f$ different from $r$, then $0 = f(s) = (s-r)g(s)$; since $(s-r)\neq 0$, then $g(s)=0$. That is, all other roots of $f$ come from roots of $g$. By the induction hypothesis, $g$ has at most $n-1$ roots. So $f$ has at most $1+n-1 = n$ roots.
This proves that, whether $f$ has at least one root or no roots, it has at most $n$ roots, proving the result.

The argument here is the same. If $f(x)\equiv 0 \pmod{p}$ has no solutions, then you are already done: $0$ is less than $n$. So we can consider the case in which there is at least one solution. It's not that the conclusion will not hold in this latter case (in fact, we will prove it does), it's that the conclusion does not immediately follow: from "at least one solution" we cannot immediately conclude "at most $n$ solutions", whereas from "no solutions" we can immediately conclude "and so at most $n$ (since $0$ is less than $n$)".
Now, we use a lemma:
Lemma. Let $r$ be any integer. Then for any nonnegative integer $t$, $x-r$ divides $x^t - r^t$.
Proof. Simply note that
$$(x-r)(x^{t-1}+x^{t-2}r+\cdots +xr^{t-2}+r^{t-1}) = x^t-r^t.\quad\Box$$
Note well: The fact that $x-r$ divides $x^t-r^t$ does not depend on whether $r$ is a root of $f(x)$ or not: it's a simple algebraic fact. It's always true.
Now, if $f(x)$ does have roots modulo $p$, then it has at least one; call it $r$. If $f(x)\equiv 0\pmod{p}$ has at least one root $r$, then we have $f(r)\equiv 0\pmod{p}$. We have
$$\begin{align*}
f(x) &\equiv f(x) - 0\pmod{p}\\
&\equiv f(x) -f(r)\pmod{p}\\
&\equiv a_nx^n + \cdots + a_0 - (a_nr^n +\cdots + a_0)
\pmod{p}\\
&\equiv a_n(x^n - r^n) + a_{n-1}(x^{n-1}-r^{n-1}) + \cdots + a_1(x-r) + (a_0-a_0)\pmod{p}
\end{align*}$$
Now, by the Lemma, $(x-r)$ divides each of $x^n-r^n$, $x^{n-1}-r^{n-1},\ldots,x-r$. So $x-r$ divides 
$$a_n(x^n-r^n)+a_{n-1}(x^{n-1}-r^{n-1}) + \cdots + a_1(x-r).$$
(This argument takes the place of the Factor Theorem in the case above).
The conclusion is that if $f(r)\equiv 0\pmod{n}$, then we can write 
$$f(x) \equiv (x-r)g(x)\pmod{p}$$
for some polynomial $g(x)$ with integer coefficients. Now the argument proceeds as in the real case: if $f(s)\equiv 0\pmod{p}$, then $(s-r)g(s)\equiv 0 \pmod{p}$, so $g(s)\equiv 0\pmod{p}$. So any other root of $f$ gives a root of $g$, and since $g$ has at most $n-1$ roots modulo $p$, then $f$ has at most $1+(n-1)=n$ roots modulo $p$. 
