code: def legendre_symbol(a, p):
      r"""
      Returns the Legendre symbol `(a / p)`.
  
      For an integer ``a`` and an odd prime ``p``, the Legendre symbol is
      defined as
  
      .. math ::
          \genfrac(){}{}{a}{p} = \begin{cases}
               0 & \text{if } p \text{ divides } a\\
               1 & \text{if } a \text{ is a quadratic residue modulo } p\\
              -1 & \text{if } a \text{ is a quadratic nonresidue modulo } p
          \end{cases}
  
      Parameters
      ==========
  
      a : integer
      p : odd prime
  
      Examples
      ========
  
      >>> from sympy.ntheory import legendre_symbol
      >>> [legendre_symbol(i, 7) for i in range(7)]
      [0, 1, 1, -1, 1, -1, -1]
      >>> sorted(set([i**2 % 7 for i in range(7)]))
      [0, 1, 2, 4]
  
      See Also
      ========
  
      is_quad_residue, jacobi_symbol
  
      """
      a, p = as_int(a), as_int(p)
      if p == 2 or not isprime(p):
          raise ValueError("p should be an odd prime")
      return int(legendre(a, p))
  
imports: from __future__ import annotations
  from sympy.external.gmpy import gcd, lcm, invert, sqrt, legendre, jacobi, kronecker, bit_scan1, remove
  from sympy.polys import Poly
  from sympy.polys.domains import ZZ
  from sympy.polys.galoistools import gf_crt1, gf_crt2, linear_congruence, gf_csolve
  from .primetest import isprime
  from .factor_ import factorint, _perfect_power
  from .modular import crt
  from sympy.utilities.decorator import deprecated
  from sympy.utilities.memoization import recurrence_memo
  from sympy.utilities.misc import as_int
  from sympy.utilities.iterables import iproduct
  from sympy.core.random import _randint, randint
  from itertools import product
label_desc: Use image node_id 19 for calling a global function with example usage: legendre_symbol(a, p) and returns: int