import math


def negative_binomial(x, k, p):
    """
    Evaluate the negative binomial distribution b*(x; k, p) as defined in the textbook.

    Equivalent to finding the probability of coin flip x to be the k-th head when the
    probability of getting a head on any one coin flip is p.

    Found with the equation (x-1)C(k-1) * p^k * (1 - p)^(x - k)
    """
    return math.comb(x - 1, k - 1) * (p ** k) * ((1 - p) ** (x - k))