def inverse(a, n):
    """Find the inverse of a modulo n if it exists"""
    t = 0
    newt = 1
    r = n
    newr = a
    while newr != 0:
        quotient = int((r - (r % newr)) / newr)
        tt = t
        t = newt
        newt = tt - quotient * newt
        rr = r
        r = newr
        newr = rr - quotient * newr
    if r > 1:
        return "a is not invertible"
    if t < 0:
        t = t + n
    return t