0

How to solve (a! / (b! * c!)) % mod. Here a! is factorial of a.

Just as (a + b) % mod = (a % mod + b % mod) % mod

I know to calculate (a * b) % mod.

But how to take modulus of this type of function?

UPDATED: Whats the best way to find (a / (b * c)) % mod. Here mod is prime number.

ElChiniNet
  • 2,778
  • 2
  • 19
  • 27
user3306991
  • 145
  • 9

1 Answers1

-1

Note that (a! / (b! * c!)) % M equals ((a! % M) / ((b! % M) * (c! % M))) % M so implement x! % M:

def modfac(x, M):
    if x == 0:
        return 1
    else:
        return (modfac(x-1, M)*x)%M

That could be made iterative but its only an example.

And then use it:

(modfac(a,M) / (modfac(b,M) * modfac(c,M))) % M
Dan D.
  • 73,243
  • 15
  • 104
  • 123
  • For computing n! mod M quickly, see [this thread](http://stackoverflow.com/questions/9727962/fast-way-to-calculate-n-mod-m-where-m-is-prime) – Ted Hopp Feb 23 '14 at 07:17
  • @DanD WHat if denomnator term overflow the range of integer?should we compute denominator modulo using inverse modulo or so?I mean question reduces now to (a/(b*c))%mod – user3306991 Feb 23 '14 at 07:31