code: def invert(a, b):
      
      if HAVE_GMP:
          s = int(gmpy2.invert(a, b))
          # according to documentation, gmpy2.invert might return 0 on
          # non-invertible element, although it seems to actually raise an
          # exception; for consistency, we always raise the exception
          if s == 0:
              raise ZeroDivisionError('invert() no inverse exists')
          return s
      else:
          r, s, _ = extended_euclidean_algorithm(a, b)
          if r != 1:
              raise ZeroDivisionError('invert() no inverse exists')
          return s % b
docs: The multiplicitive inverse of a in the integers modulo b.
  
      :return int: x, where a * x == 1 mod b