Compute nCr % m

Given three integers A, B and C, where A represents n, B represents r and C represents m,
find and return the value of nCr % m where nCr % m = (n! / ((n-r)! * r!)) % m.

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



Input Format

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

Output Format

Return the value of nCr % m.

Constraints

1 <= A*B <= 10^6
1 <= B <= A
1 <= C <= 10^6

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 % m on Interview Code Editor
Hints
  • Hints are not available for this problem

Discussion


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