def _modinv(e, m):
 (x1, y1, x2, y2) = (1, 0, 0, 1)
 (a, b) = (e, m)
 while (b > 0):
  (q, r) = divmod(a, b)
  (xn, yn) = ((x1 - (q * x2)), (y1 - (q * y2)))
  (a, b, x1, y1, x2, y2) = (b, r, x2, y2, xn, yn)
 return (x1 % m)

def _modinv ( e , m ) : ( x1 , y1 , x2 , y2 ) = ( 1 , 0 , 0 , 1 ) ( a , b ) = ( e , m ) while ( b > 0 ) : ( q , r ) = divmod ( a , b ) ( xn , yn ) = ( ( x1 - ( q * x2 ) ) , ( y1 - ( q * y2 ) ) ) ( a , b , x1 , y1 , x2 , y2 ) = ( b , r , x2 , y2 , xn , yn ) return ( x1 % m )
modular multiplicative inverse .