def _primitive_root_prime_iter(p):
 p = as_int(p)
 v = [((p - 1) // i) for i in factorint((p - 1)).keys()]
 a = 2
 while (a < p):
  for pw in v:
   if (pow(a, pw, p) == 1):
    break
  else:
   (yield a)
  a += 1

def _primitive_root_prime_iter ( p ) : p = as_int ( p ) v = [ ( ( p - 1 ) // i ) for i in factorint ( ( p - 1 ) ) . keys ( ) ] a = 2 while ( a < p ) : for pw in v : if ( pow ( a , pw , p ) == 1 ) : break else : ( yield a ) a += 1
generates the primitive roots for a prime p references .