问题描述:
Write a function to compute the value of ncr%p.

测试用例:
['assert ncr_modp(10,2,13)==6', 'assert ncr_modp(15,12,43)==25', 'assert ncr_modp(17,9,18)==10']

生成的代码:
def ncr_modp(n, r, p):
    if r > n:
        return 0

    # Function to compute factorial % p
    def factorial_mod(n, p):
        result = 1
        for i in range(2, n + 1):
            result = (result * i) % p
        return result

    # Function to compute modular inverse using Fermat's Little Theorem
    def mod_inverse(a, p):
        return pow(a, p - 2, p)

    # Calculate n!, r! and (n-r)!
    num = factorial_mod(n, p)
    denom = (factorial_mod(r, p) * factorial_mod(n - r, p)) % p

    # Calculate nCr % p
    return (num * mod_inverse(denom, p)) % p