def gcdex_diophantine(a, b, c):
 (s, g) = a.half_gcdex(b)
 q = c.exquo(g)
 s = (q * s)
 if ((not s.is_zero) and (b.degree() >= b.degree())):
  (q, s) = s.div(b)
 t = (c - (s * a)).exquo(b)
 return (s, t)

def gcdex_diophantine ( a , b , c ) : ( s , g ) = a . half_gcdex ( b ) q = c . exquo ( g ) s = ( q * s ) if ( ( not s . is_zero ) and ( b . degree ( ) >= b . degree ( ) ) ) : ( q , s ) = s . div ( b ) t = ( c - ( s * a ) ) . exquo ( b ) return ( s , t )
extended euclidean algorithm .