def legendre_symbol(a, p):
 (a, p) = (as_int(a), as_int(p))
 if ((not isprime(p)) or (p == 2)):
  raise ValueError('p should be an odd prime')
 a = (a % p)
 if (not a):
  return 0
 if is_quad_residue(a, p):
  return 1
 return (-1)

def legendre_symbol ( a , p ) : ( a , p ) = ( as_int ( a ) , as_int ( p ) ) if ( ( not isprime ( p ) ) or ( p == 2 ) ) : raise ValueError ( 'p should be an odd prime' ) a = ( a % p ) if ( not a ) : return 0 if is_quad_residue ( a , p ) : return 1 return ( - 1 )
returns the legendre symbol .