def mod_inverse(a, m):
 c = None
 try:
  (a, m) = (as_int(a), as_int(m))
  if (m > 1):
   (x, y, g) = igcdex(a, m)
   if (g == 1):
    c = (x % m)
   if (a < 0):
    c -= m
 except ValueError:
  (a, m) = (sympify(a), sympify(m))
  if (not (a.is_number and m.is_number)):
   raise TypeError(filldedent('\n                Expected numbers for arguments; symbolic `mod_inverse`\n                is not implemented\n                but symbolic expressions can be handled with the\n                similar function,\n                sympy.polys.polytools.invert'))
  big = (m > 1)
  if (not ((big is S.true) or (big is S.false))):
   raise ValueError(('m > 1 did not evaluate; try to simplify %s' % m))
  elif big:
   c = (1 / a)
 if (c is None):
  raise ValueError(('inverse of %s (mod %s) does not exist' % (a, m)))
 return c

def mod_inverse ( a , m ) : c = None try : ( a , m ) = ( as_int ( a ) , as_int ( m ) ) if ( m > 1 ) : ( x , y , g ) = igcdex ( a , m ) if ( g == 1 ) : c = ( x % m ) if ( a < 0 ) : c -= m except ValueError : ( a , m ) = ( sympify ( a ) , sympify ( m ) ) if ( not ( a . is_number and m . is_number ) ) : raise TypeError ( filldedent ( '\n                Expected numbers for arguments; symbolic `mod_inverse`\n                is not implemented\n                but symbolic expressions can be handled with the\n                similar function,\n                sympy.polys.polytools.invert' ) ) big = ( m > 1 ) if ( not ( ( big is S . true ) or ( big is S . false ) ) ) : raise ValueError ( ( 'm > 1 did not evaluate; try to simplify %s' % m ) ) elif big : c = ( 1 / a ) if ( c is None ) : raise ValueError ( ( 'inverse of %s (mod %s) does not exist' % ( a , m ) ) ) return c
return the number c such that .