TITLE: Compute the value of $M=\frac{2015!}{2002!\cdot13!}\;\bmod\;2017$
QUESTION [6 upvotes]: Recently, I have found this problem:

Given that $2017$ is a prime number, compute the value of the following expression:
$$M=\frac{2015!}{2002!\cdot13!}\;\bmod\;2017$$

I have tried two diffent ways:
-In Python I have written a small program to compute the result. Here's the code:
>>>def F(n):
   ...  if n==1:
   ...          return 1
   ...  else:
   ...          return n*F(n-1)

And:
>>>import sys
>>>sys.setrecurcionlimit(2020)
>>>M = F(2017)/(F(2002) * F(13)) % 2017

-In the second way, I have written all prime factors of $\{2015,2014,\cdots,2004,2003\}$ and then I have simplyfied the left side of the expression. I obtained:
$$M\;\bmod\;2017\equiv5\cdot7\cdot17\cdot19\cdot31\cdot41\cdot53\cdot59\cdot61\cdot67\cdot167\cdot223\cdot251\cdot401\cdot503\cdot2003\cdot2011\;\bmod\;2017$$ where all numers are primes. But how can we go on?

REPLY [3 votes]: Notice that if we let
$$ M :=\frac{2015!}{2002!\cdot13!} \mod 2017, \tag{1} $$
then by definition of binomial coefficients
$$ M \equiv \binom{ 2015}{ 13} \bmod 2017. \tag{2} $$
Now notice we are given that $2017$ is prime and
that $$ 2015 \equiv -2 \mod 2017. \tag{3} $$
If $\,p\,$ is a prime,$\,0 < n < p,\,$ and
$\,x \equiv y \mod p\,$ then
$\,\binom {x}{n} \equiv \binom{y}{n}\mod p\,$ so
$$ M \equiv \binom{ -2}{ 13} \bmod 2017. \tag{4} $$
Now we use $$ (-1)^n (n+1) = \binom{ -2}{ n} \tag{5} $$
and thus the final result is
$$ M = (-1)^{13}(13+1) = -14 \equiv 2003 \mod 2017. \tag{6}$$