def gf_eval(f, a, p, K):
 result = K.zero
 for c in f:
  result *= a
  result += c
  result %= p
 return result

def gf_eval ( f , a , p , K ) : result = K . zero for c in f : result *= a result += c result %= p return result
evaluate f(a) in gf(p) using horner scheme .