def gf_Qmatrix(f, p, K):
 (n, r) = (gf_degree(f), int(p))
 q = ([K.one] + ([K.zero] * (n - 1)))
 Q = ([list(q)] + ([[]] * (n - 1)))
 for i in range(1, (((n - 1) * r) + 1)):
  (qq, c) = ([(((- q[(-1)]) * f[(-1)]) % p)], q[(-1)])
  for j in range(1, n):
   qq.append(((q[(j - 1)] - (c * f[((- j) - 1)])) % p))
  if (not (i % r)):
   Q[(i // r)] = list(qq)
  q = qq
 return Q

def gf_Qmatrix ( f , p , K ) : ( n , r ) = ( gf_degree ( f ) , int ( p ) ) q = ( [ K . one ] + ( [ K . zero ] * ( n - 1 ) ) ) Q = ( [ list ( q ) ] + ( [ [ ] ] * ( n - 1 ) ) ) for i in range ( 1 , ( ( ( n - 1 ) * r ) + 1 ) ) : ( qq , c ) = ( [ ( ( ( - q [ ( - 1 ) ] ) * f [ ( - 1 ) ] ) % p ) ] , q [ ( - 1 ) ] ) for j in range ( 1 , n ) : qq . append ( ( ( q [ ( j - 1 ) ] - ( c * f [ ( ( - j ) - 1 ) ] ) ) % p ) ) if ( not ( i % r ) ) : Q [ ( i // r ) ] = list ( qq ) q = qq return Q
calculate berlekamps q matrix .