Legendre Symbol Calculator

Find whether a number is a quadratic residue modulo an odd prime using Euler's criterion.

Math and PercentUpdated 2026-11-203 min read
Legendre Symbol Calculator
Enter an odd prime. Composite and even values are rejected.
Legendre symbol
...
Meaning...
a to the (p-1)/2 mod p...

What it does

The Legendre symbol answers a compact question in number theory: is an integer a a perfect square modulo an odd prime p? The answer is written as a fraction-like symbol with a on top and p below, and it takes only three values. It is 1 when a square root exists, -1 when none exists and 0 when p divides a.

Euler's criterion gives a direct way to compute it. Raise a to the power (p minus one) divided by two and reduce modulo p. The result is 1 for a residue and p minus one for a nonresidue, which represents minus one in modular arithmetic. The tool performs this with repeated squaring so there is no floating point overflow.

For small primes you can also list the squares. Modulo 7 the squares of 1 through 6 are 1, 4, 2, 2, 4 and 1, so the residues are 1, 2 and 4 while 3, 5 and 6 are nonresidues. The calculator agrees with that list, giving a symbol of 1 for 2 and minus 1 for 3.

The modulus must be an odd prime. The tool tests this before doing any exponentiation and returns a clear error for composite or even values. The top argument may be any integer, including negative numbers and multiples of p, because the computation reduces it into the range from zero to p minus one first.

The symbol is the starting point for quadratic reciprocity, which lets you swap numerator and denominator under certain conditions. It is used in primality tests, cryptography and the study of conic equations over finite fields. This page computes the symbol itself and does not attempt the full reciprocity law.

How to use

  1. Enter the integer whose residue status you want to check.
  2. Enter an odd prime as the modulus.
  3. Read the symbol, the plain language meaning and the modular power result.
  4. Check that the power result is 1 or p minus one, as Euler's criterion requires.
  5. Try a multiple of p to see the zero case.
  6. Use another prime to see how the residue set changes.

Formula

(a/p) = a^((p-1)/2) mod p, for odd prime p. The result is 1, -1 or 0.
a
Any integer, reduced modulo p before exponentiation.
p
An odd prime modulus.
(a/p)
The Legendre symbol, taking values 1, -1 or 0.
a^((p-1)/2) mod p
Euler's criterion, the value computed by the tool.

When p divides a, the symbol is 0 and no exponentiation is needed. For other values, Euler's criterion guarantees the modular power is either 1, written as symbol 1, or p minus one, written as symbol -1. If a composite modulus is entered, the criterion no longer applies and the tool returns an error instead of a misleading answer.

Worked example

Example: a = 2 and p = 7

Defaults: a = 2 and p = 7.

  1. Check that 7 is an odd prime and reduce 2 modulo 7, which is still 2.
  2. Compute the exponent: (7 - 1) / 2 = 3.
  3. Raise 2 to the power 3: 2³ = 8.
  4. Reduce modulo 7: 8 mod 7 = 1.
  5. Euler's criterion gives symbol 1, meaning quadratic residue.
  6. The tool shows 1, Quadratic residue and 1.

Reference table

Squares and Legendre symbols modulo 7
Value aSquare root existsSymbol
1Yes1
2Yes1
3No-1
4Yes1
5No-1
6No-1
0Divisible by 70

Limits

  • Only accepts odd prime moduli, so composite and even values are rejected.
  • Computes the symbol only, not the actual square root of a residue.
  • Does not apply quadratic reciprocity or handle Jacobi symbols for composite moduli.
  • The largest accepted prime is 1,000,003.

Common mistakes

  • Entering an even number or a composite number as the modulus.
  • Reading symbol -1 as a negative residue rather than a nonresidue.
  • Forgetting that multiples of p give symbol 0.
  • Confusing this symbol with an ordinary fraction.
  • Expecting the tool to return the square root when the symbol is 1.

Try it yourself

Quick checks. Answers sit tucked under each question.

What does the tool show for a = 3 and p = 7?

The exponent is 3 and 3³ = 27. Modulo 7 that is 6, which is p minus one, so the symbol is -1 and the tool reports Quadratic nonresidue.

What if a equals p, for example 7 and 7?

The top argument reduces to 0, so the tool shows symbol 0, Divisible by p and power result 0.

Check a = 5 and p = 29. What is the verdict?

The exponent is 14 and 5 to the 14th power is congruent to 1 modulo 29, so the symbol is 1 and the tool reports Quadratic residue.

Questions

What does the Legendre symbol tell me?

Whether an integer has a square root modulo an odd prime, encoded as 1 for yes, -1 for no and 0 when the prime divides the integer.

What is Euler's criterion?

The result that a to the power (p-1)/2 modulo p equals the Legendre symbol, taking the value p minus one to represent minus one.

Why must p be prime?

Euler's criterion and the three valued symbol are defined for odd primes. Composite moduli use the related Jacobi symbol instead.

How do negative inputs work?

The tool reduces a into the range from 0 to p minus one first, so negative integers are handled correctly.

Can I use p = 2?

No. Two is the only even prime and the Legendre symbol is defined for odd primes, so the tool rejects it.

Does the tool find the square root?

No. It only decides whether a square root exists. Finding one needs a separate modular square root algorithm.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.