Leandro Junes

Legendre Symbol

Evaluate the Legendre symbol (a/p) for an integer a and an odd prime p. The result is 0 if p | a, 1 if a is a nonzero quadratic residue modulo p, and −1 otherwise.

Inputs

Any integer.

Odd prime greater than 2.

The modulus is checked with the site's primality classifier: below 3.3 × 10²⁴ the answer is exact, above it p is only a probable prime and the result is labeled as assuming p is prime. Computation runs locally in your browser.

Try

Result

—

—

Solution steps

—

    Method

    For an odd prime p the Legendre symbol is

    (a/p) = 0 if p | a; 1 if a is a nonzero square mod p; −1 if a is a nonresidue.

    The value 1 means a nonzero quadratic residue: some integer x satisfies x² ≡ a (mod p). This calculator decides whether such an x exists; it does not compute it.

    Euler's criterion. If p ∤ a, Fermat's theorem gives a^(p−1) ≡ 1 (mod p), and the half-power refines it:

    a^((p−1)/2) ≡ (a/p) (mod p).

    So the half-power is 1 for a quadratic residue and −1 for a nonresidue. The calculator reduces a modulo p, handles p | a and a ≡ 1 directly, and otherwise computes a₀^((p−1)/2) mod p by modular exponentiation. For a prime p the residue is always 1 or p-1; any other residue proves that p is composite, and then no symbol value is given.

    Exact or conditional. If p is below 3.3 × 10²⁴ it is proven prime and the answer is exact. Above that the site's classifier only establishes a probable prime, and the result is reported as assuming p is prime.

    Supplementary laws.

    (−1/p) = (−1)^((p−1)/2): 1 if p ≡ 1 (mod 4), −1 if p ≡ 3 (mod 4).
    (2/p) = (−1)^((p²−1)/8): 1 if p ≡ ±1 (mod 8), −1 if p ≡ ±3 (mod 8).

    Quadratic reciprocity. For distinct odd primes p and q:

    (p/q)(q/p) = (−1)^((p−1)(q−1)/4).

    Equivalently (p/q) = (q/p) unless both primes are congruent to 3 modulo 4, in which case the sign changes. It is not used by this calculator.

    Group-theory view. The group of units (ℤ/pℤ)^× has order p-1. The nonzero squares form a subgroup of index 2, so they contain (p-1)/2 elements: exactly half of the nonzero residue classes are quadratic residues. If g is a primitive root modulo p, then (g/p) = −1, because g has order p-1 and cannot lie in a subgroup of order (p-1)/2.

    Related: Primality Test · Modular Exponentiation · Primitive Roots · Multiplicative Order