def METHOD_NAME(a, p):
    x, y, m = 1, 0, p
    while a > 1:
        q = a // m
        t = m
        m = np.mod(a, m)
        a = t
        t = y
        y, x = x - np.int64(q) * np.int64(y), t
        if x < 0:
            x = np.mod(x, p)
    return np.mod(x, p)