def binom_modulo(n, k, p):
    """Binomial coefficients for :math:`n \choose k`, modulo p

    :param n,k: non-negative integers
    :complexity: O(k)
    """
    prod = 1
    for i in range(k):
        prod = (prod * (n - i) * inv(i + 1, p)) % p
    return prod