TITLE: Computing the last non-zero digit of ${1027 \choose 41}$?
QUESTION [10 upvotes]: I am working on the following problem:
Let $x_n$ be a sequence of positive odd numbers. If $N$ is the number of ordered pairs $(x_1, x_2, x_3, \dots, x_{42})$ such that $$x_1 + x_2 + x_3 + \dots + x_{42} = 2014,$$
then find $N \pmod {1000}$
My progress: Let $x_n = 2a_n + 1$, with $a_n \geq 0$. Then $$a_1 + a_2 + a_3 + \dots + a_{42} = 986$$
By stars and bars, this equals ${1027 \choose 41}$.
To find what this is equal to $\pmod {1000}$, I first computed the number of $5$s in it. I found that there were $2$ more $5$s in the numerator, and I am sure there are at least $2$ more $2$s in the numerator as well (the top has $2^{10} = 1024$), so there are two ending zeros. However, I do not know how I might find the last non-zero digit of this number.

REPLY [3 votes]: I was able to solve the problem by using one of the generalizations to Lucas' theorem (taken from page 2 of the wonderful paper Binomial coefficients modulo prime power).
$$\dfrac1{p^k}\binom{n}{m}\equiv(-1)^k\left(\dfrac{n_0!}{m_0!r_0!}\right)\left(\dfrac{n_1!}{m_1!r_1!}\right)\cdots\left(\dfrac{n_d!}{m_d!r_d!}\right)\pmod{p}$$
where $r = n -m$ and $n_i, m_i, r_i$ are the $i$th digits in the base $p$ representation of $n, m, r$ respectively. $k$ is the largest power of $p$ dividing $\binom{n}{m}$.
We have $n=1027, m = 41, r = 986$. In base $p=5$, $n = (13102)_5, m = (00131)_5, r = (12421)_5$.
The above result gives 
$\begin{align}\frac{1}{5^k}\binom{1027}{41} &\equiv (-1)^k\left(\frac{1!}{0!1!}\right)\left(\frac{3!}{0!2!}\right)\left(\frac{1!}{1!4!}\right)\left(\frac{0!}{3!2!}\right)\left(\frac{2!}{1!1!}\right) \mod{5}\\&\equiv (-1)^k \left(\frac{1}{1}\right) \left(\frac{6}{2}\right)\left(\frac{1}{24}\right)\left(\frac{1}{12}\right)\left(\frac{2}{1}\right) \mod{5}\\&\equiv (-1)^k \cdot 1 \cdot 3 \cdot 4 \cdot 3 \cdot 2 \mod{5}\\&\equiv (-1)^k \cdot 2 \mod{5}\end{align}$
We get $2$ carries when adding $m$ and $r$ in base $5$, so from Kummer's theorem, $k=2$.
$\begin{array}{c}\color{blue}{\text{carry}}&\color{blue}{0}&\color{blue}{0}&\color{blue}{1}&\color{blue}{1}&\color{blue}{0}\\m&-&0&0&1&3&1\\r&-&1&2&4&2&1\\\hline \\m+r&-&1&3&1&0&2\end{array}$
We thus have
$\begin{align}\frac{1}{5^2}\binom{1027}{41} &\equiv (-1)^2 \cdot 2 \mod{5}\\\iff \frac{1}{5^2}\binom{1027}{41}&=5j + 2 \text{ where } j \in \mathbb{N}\\\iff\binom{1027}{41} &= 125j + 50\\\iff\binom{1027}{41} &\equiv 50 \mod{125}\end{align}$
Similar steps for base $p=2$ give $\begin{align}\binom{1027}{41} &\equiv 0 \mod{8}\end{align}$
And so we get our answer:
$\begin{align}x&\equiv \binom{1027}{41} (\text{mod }{1000})\equiv 50 (\text{mod }{125})\equiv 0 (\text{mod }{8})\\\implies x &\in \{50, 175, 300, 425, 550, 675, \color{green}{800}, 975\} \cap \{0, 8, 16, \cdots, 792, \color{green}{800}, 808, \cdots 992\}\\\implies x &= {800}\end{align}$