nCr mod 10^9 + 7 for n<=10^9 and r <=1000

325 Views Asked by At

This may have been asked before but none of the answers I saw worked for me. I tried Lucas Theorem,Fermat's theorem but none of them worked. Is there an efficient way to find the value of:

nCr mod 10^9+7 where n<=10^9 and r<=1000

Any help will be very useful

1

There are 1 best solutions below

0
user2341726 On BEST ANSWER

n is large while r is small, you are better off compute nCr by n(n-1)...(n-r+1)/(1*2*...*r)

You may need to find multiplicate inverse of 1, 2, ... r mod 10^9+7