Update appNew update is available. Click here to update.

Fermat Little Theorem

Last Updated: 17 Jun, 2021
Difficulty: Moderate


Try Problem

You are given two integers 'n' and 'r' and a prime number 'p'. Your task is to find (nCr) % p where nCr can be calculated as n! / (r! * (n - r)!).

Note :

N!  =  1 * 2 * 3 *... N
Input format :
The first line of input contains a single integer 'T', representing the number of test cases. 

The first line of each test case contains three space-separated integers 'n', 'r', and 'p'.
Output format :
For each test case, print a single line containing an integer representing the value of (nCr) % p.

The output of each test case will be printed on a separate line.
You don't need to input or print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 5 
1 <= n, r, p <= 5 * 10 ^ 2
p is prime number.

Time limit: 1 sec.