Leandro Junes

Jacobi Symbol

Evaluate the Jacobi symbol (a/n) for an integer a and a positive odd integer n. The Jacobi symbol generalizes the Legendre symbol to positive odd composite denominators; n does not have to be prime and is never factored.

Inputs

Any integer.

Odd integer ≥ 1.

Jacobi is not Legendre For a prime p, (a/p) = 1 means a is a nonzero quadratic residue. For a composite n, (a/n) = 1 does not mean that. For example (2/15) = (2/3)(2/5) = (−1)(−1) = 1, yet x² ≡ 2 (mod 15) has no solution.
Try

Result

—

—

Reciprocity steps

—

RuleSymbol after the stepSign factorRunning sign

Method

Definition. If n = p₁^e₁ ⋯ p_r^e_r is the prime factorization of the positive odd integer n, then

(a/n) = ∏ (a/p_i)^e_i, (a/1) = 1.

Why factoring is unnecessary. This is the definition, not the algorithm. Like the Legendre symbol, the Jacobi symbol obeys the laws below, so it can be evaluated by a Euclid-like procedure that never factors n. For example, (2/15): 15 ≡ 7 (mod 8), so the supplementary law for 2 gives no sign change and (2/15) = 1 at once, with no need to write 15 = 3·5. The factored computation above agrees.

Remove powers of 2. For positive odd n:

(2/n) = (−1)^((n²−1)/8); (−1/n) = (−1)^((n−1)/2).

Each factor 2 removed from the numerator contributes this sign.

Apply quadratic reciprocity. For positive odd coprime m and n:

(m/n)(n/m) = (−1)^((m−1)(n−1)/4).

The sign changes exactly when m ≡ n ≡ 3 (mod 4).

Reduce as in Euclid's algorithm. After swapping, replace the new numerator by its remainder modulo the new denominator and repeat. The numerator eventually reaches 0. If the last denominator is 1 the answer is the accumulated sign; otherwise it is 0, and that last denominator is gcd(a, n) > 1. The procedure behaves like the Euclidean algorithm, so it handles very large integers without factoring the denominator.

Multiplicativity.

(ab/n) = (a/n)(b/n), (a/mn) = (a/m)(a/n).

Interpreting the value. For n>1: (a/n) = 0 exactly when gcd(a, n) > 1. The value -1 certifies that a is a quadratic nonresidue: if a were a square modulo n with gcd(a, n) = 1, it would be a square modulo every prime p dividing n, so every Legendre symbol would be 1 and the product could not be -1. The value +1 certifies nothing when n is composite: two nonresidues modulo different primes multiply to +1. If n is prime the Jacobi symbol equals the Legendre symbol, and then +1 does mean that a is a nonzero quadratic residue.

Difference from the Legendre symbol. The Legendre symbol requires a prime denominator and answers the residuosity question; the Jacobi symbol accepts any positive odd denominator and answers only the sign question above. This calculator does not test n for primality and does not compute square roots.

Related: Legendre Symbol · Primality Test · Modular Exponentiation