Factorials for large numbers

I’ve come across various problems where we need to present a solution modulus 1000000007 (M). Most of these problems involve calculating permutations and combinations involving big numbers. One such problem is MOVES The solution is presented here.

In this solution (and many others where we need to calculate permutations and combinations), a
factorial lookup table has been constructed. In addition to this, there’s another table which carries the lookup values of factorial of a number in denominator. e.g. for C(n,r) = n!/((n-r!)r!), two tables are used - fact and inverseFact. So C(n,r) is just a lookup == fact(n) x (inverseFact(n-r)%M) x (inverseFact®%M)

How is this inverseFact - (1/(N!)%M) lookup table constructed ? IT would be great in case any one can point me to the actual theory behind this.

@gamabunta described this at the end of his perfect answer here :wink:

1 Like

Thnx a ton. This really helps.