Finding binomial coefficient for large n and k modulo m
问题 I want to compute nCk mod m with following constraints: n<=10^18 k<=10^5 m=10^9+7 I have read this article: Calculating Binomial Coefficient (nCk) for large n & k But here value of m is 1009. Hence using Lucas theorem, we need only to calculate 1009*1009 different values of aCb where a,b<=1009 How to do it with above constraints. I cannot make a array of O(m*k) space complexity with given constraints. Help! 回答1: Just use the fact that (n, k) = n! / k! / (n - k)! = n*(n-1)*...*(n-k+1)/[k*(k-1)