def dup_pow(f, n, K):
 if (not n):
  return [K.one]
 if (n < 0):
  raise ValueError("can't raise polynomial to a negative power")
 if ((n == 1) or (not f) or (f == [K.one])):
  return f
 g = [K.one]
 while True:
  (n, m) = ((n // 2), n)
  if (m % 2):
   g = dup_mul(g, f, K)
   if (not n):
    break
  f = dup_sqr(f, K)
 return g

def dup_pow ( f , n , K ) : if ( not n ) : return [ K . one ] if ( n < 0 ) : raise ValueError ( "can't raise polynomial to a negative power" ) if ( ( n == 1 ) or ( not f ) or ( f == [ K . one ] ) ) : return f g = [ K . one ] while True : ( n , m ) = ( ( n // 2 ) , n ) if ( m % 2 ) : g = dup_mul ( g , f , K ) if ( not n ) : break f = dup_sqr ( f , K ) return g
raise f to the n-th power in k[x] .