def hook_index(n: int, t: int) -> int:
    """For integers n and t, finds the largest number not greater than n such that the binary
    representation of n has exactly t zeros."""
    d = 1 << t
    r = n & ~(d - 1)  # zero the last t bits of n
    if n & d != 0:
        return r
    else:
        return (r - 1) & ~(d - 1)