I am trying to calculate $\binom{n}{r}$ modulo $1000000007$. I have read here about Lucas' Theorem but it seems to work for small values of $p$. Here $p = 1000000007$. Is there a way this can be solved? Thank you.
Calculating $\binom{n}{r} \bmod\; p$ where $p$ is prime and as large as $1000000007$
2
$\begingroup$
combinatorics
permutations
-
0Yes, this is from a contest. I have the idea how to solve the problem, but this comes in the way to solve it. – 2012-12-03
1 Answers
1
By Legendre formula $ \Large n!=\prod\limits_{p\in P,p\leq n} p^{\left(\sum\limits_{1\leq k\leq \log_p n}\left\lfloor\frac{n}{p^k}\right\rfloor\right)} $ where $P$ is the set of prime numbers. So to solve the problem you need to precompute primes less than $n$, and then optimize computation of formula given above.