def is_quad_residue(a, p):
 (a, p) = (as_int(a), as_int(p))
 if (p < 1):
  raise ValueError('p must be > 0')
 if ((a >= p) or (a < 0)):
  a = (a % p)
 if ((a < 2) or (p < 3)):
  return True
 if (not isprime(p)):
  if ((p % 2) and (jacobi_symbol(a, p) == (-1))):
   return False
  r = sqrt_mod(a, p)
  if (r is None):
   return False
  else:
   return True
 return (pow(a, ((p - 1) // 2), p) == 1)

def is_quad_residue ( a , p ) : ( a , p ) = ( as_int ( a ) , as_int ( p ) ) if ( p < 1 ) : raise ValueError ( 'p must be > 0' ) if ( ( a >= p ) or ( a < 0 ) ) : a = ( a % p ) if ( ( a < 2 ) or ( p < 3 ) ) : return True if ( not isprime ( p ) ) : if ( ( p % 2 ) and ( jacobi_symbol ( a , p ) == ( - 1 ) ) ) : return False r = sqrt_mod ( a , p ) if ( r is None ) : return False else : return True return ( pow ( a , ( ( p - 1 ) // 2 ) , p ) == 1 )
returns true if a is in the set of squares mod p .