Compute nCr % p

Given three integers A, B and C, where A represents n, B represents r and C represents p
and p is a prime number greater than n, find and return the value of nCr % p where
nCr % p = (n! / ((n-r)! * r!)) % p.

x! means factorial of x i.e. x! = 1 * 2 * 3… * x.



Input Format

The first argument given is the integer A ( = n).
The second argument given is the integer B ( = r).
The third argument given is the integer C ( = p).

Output Format

Return the value of nCr % m.

Constraints

1 <= A <= 10^6
1 <= B <= A
A <= C <= 10^9 + 7

For Example

Input 1:
    A = 5
    B = 2
    C = 13
Output 1:
    10

Input 2:
    A = 6
    B = 2
    C = 13
Output 2:
    2
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Compute nCr % p on Interview Code Editor
Hints
  • Hints are not available for this problem

Discussion


Loading...
Click here to start solving coding interview questions