Lucas' Theorem

Theorem
Let $p$ be a prime number.

Let $n, k \in \Z_{\ge 0}$.

Then:
 * $\dbinom n k \equiv \dbinom {\left \lfloor {n / p} \right \rfloor} {\left \lfloor {k / p} \right \rfloor} \dbinom {n \bmod p} {k \bmod p} \pmod p$

where:
 * $\dbinom n k$ denotes a binomial coefficient
 * $n \bmod p$ denotes the modulo operation
 * $\left \lfloor \cdot \right \rfloor$ denotes the floor function.

Proof
First we show that:
 * $\dbinom n k \equiv \dbinom {\left \lfloor {n / p} \right \rfloor} {\left \lfloor {k / p} \right \rfloor} \dbinom {n \bmod p} {k \bmod p} \pmod p$

Consider $\dbinom n k$ as the fraction:
 * $\dfrac {n \left({n - 1}\right) \left({n - 2}\right) \cdots \left({n - k + 1}\right)} {k \left({k - 1}\right) \left({k - 2}\right) \cdots 1}$

This can be expressed as:
 * $(1): \quad \dbinom n k = \left({\dfrac n k}\right) \left({\dfrac {n - 1} {k - 1} }\right) \left({\dfrac {n - 2} {k - 2} }\right) \cdots \left({\dfrac {n - k + 1} 1}\right)$

Let $k = s p + t$ from the Division Theorem.

Thus:
 * $t = k \bmod p$

The denominators of the first $t$ factors in $(1)$ do not have $p$ as a divisor.

Now let $n = u p + v$, again from the Division Theorem.

Thus:
 * $v = n \bmod p$

Now, when dealing with non-multiples of $p$, we can work modulo $p$ in both the numerator and denominator, from Common Factor Cancelling in Congruence.

So we consider the first $t$ factors of $(1)$ modulo $p$.

These are:
 * $\left({\dfrac {u p + v} {s p + t} }\right) \left({\dfrac {u p + v - 1} {s p + t - 1} }\right) \cdots \left({\dfrac {u p + v - t + 1} {s p + 1} }\right) \equiv \left({\dfrac v t}\right) \left({\dfrac {v - 1} {t - 1} }\right) \cdots \left({\dfrac {v - t + 1} 1}\right) \pmod p$

So, these first $t$ terms of $(1)$ taken together are congruent modulo $p$ to the corresponding terms of:
 * $\dbinom {n \bmod p} {k \bmod p}$

These differ by multiples of $p$.

So we are left with $k - k \bmod p$ factors.

These fall into $\left \lfloor {k / p} \right \rfloor$ groups, each of which has $p$ consecutive values.

Each of these groups contains exactly one multiple of $p$.

The other $p - 1$ factors in a given group are congruent (modulo $p$) to $\left({p - 1}\right)!$ so they cancel out in numerator and denominator.

We now need to investigate the $\left \lfloor {k / p} \right \rfloor$ multiples of $p$ in the numerator and denominator.

We divide each of them by $p$ and we are left with the binomial coefficient:
 * $\dbinom {\left \lfloor {\left({n - k \bmod p}\right) / p} \right \rfloor} {\left \lfloor {k / p} \right \rfloor}$

Now, if $k \bmod p \le n \bmod p$, this equals:
 * $\dbinom {\left \lfloor {n / p} \right \rfloor} {\left \lfloor {k / p} \right \rfloor}$

Otherwise, if $k \bmod p > n \bmod p$, the other factor:
 * $\dbinom {n \bmod p} {k \bmod p}$

is zero.

So the formula holds in general.