def gf_quo(f, g, p, K):
 df = gf_degree(f)
 dg = gf_degree(g)
 if (not g):
  raise ZeroDivisionError('polynomial division')
 elif (df < dg):
  return []
 inv = K.invert(g[0], p)
 (h, dq, dr) = (f[:], (df - dg), (dg - 1))
 for i in range(0, (dq + 1)):
  coeff = h[i]
  for j in range(max(0, (dg - i)), (min((df - i), dr) + 1)):
   coeff -= (h[((i + j) - dg)] * g[(dg - j)])
  h[i] = ((coeff * inv) % p)
 return h[:(dq + 1)]

def gf_quo ( f , g , p , K ) : df = gf_degree ( f ) dg = gf_degree ( g ) if ( not g ) : raise ZeroDivisionError ( 'polynomial division' ) elif ( df < dg ) : return [ ] inv = K . invert ( g [ 0 ] , p ) ( h , dq , dr ) = ( f [ : ] , ( df - dg ) , ( dg - 1 ) ) for i in range ( 0 , ( dq + 1 ) ) : coeff = h [ i ] for j in range ( max ( 0 , ( dg - i ) ) , ( min ( ( df - i ) , dr ) + 1 ) ) : coeff -= ( h [ ( ( i + j ) - dg ) ] * g [ ( dg - j ) ] ) h [ i ] = ( ( coeff * inv ) % p ) return h [ : ( dq + 1 ) ]
compute exact quotient in gf(p)[x] .