# Number of solutions to $f(n) \equiv 0 \pmod{p}$ where $f$ is a cubic

Let $f(x)$ be a cubic polynomial (not necessarily irreducible over $\mathbb{Z}[x]$). Fix a prime $p$. Are there any ways to tell when $f(n) \equiv 0 \pmod{p}$ has 3, 2, 1, or 0 solutions?

-
An obvious idea that comes to mid is trying all $p$ possible values. Is $p$ assumed to be so large that this would be impractical? –  Marc van Leeuwen Mar 21 '13 at 12:55

$\mathbb{F}_p$ is a field, so most stuff that works for reals works here too. You can look for Cardano's formula, but you end up taking roots. To see if there are repeat roots, compute $\gcd(p'(x), p(x))$ (the formal derivative is computed as for the reals, and as there any common factors between $p(x)$ and $p'(x)$ are for roots of multiplicity greater than 1). There are algorithms for factoring polynomials, symbolic mathematics packages like PARI/GP or SAGE probably include them.