On this page
The Legendre symbol asks whether a is a square modulo a prime p. The Jacobi symbol keeps the notation, (a/n), but lets the bottom be any odd positive integer. That makes it fast to compute, and easy to misread.
What is the Jacobi symbol?
The Jacobi symbol was introduced by Jacobi in 1837 as a generalisation of the Legendre symbol.
For an odd positive n = p₁^α₁ ⋯ p_k^α_k, the Jacobi symbol (a/n) is the product (a/p₁)^α₁ ⋯ (a/p_k)^α_k of Legendre symbols, as the same Wikipedia article defines it. Each factor (a/p) is 0 if p divides a, +1 if a is a nonzero square mod p, and −1 otherwise. So (a/n) is 0 when a and n share a factor and ±1 otherwise. New to squares mod a prime? Start with our explainer on quadratic residues and the Legendre symbol.
Which rules let you compute it without factoring?
Five rules from the Wikipedia article do all the work:
Reduce: if a ≡ b (mod n), then (a/n) = (b/n).
Multiply on top: (ab/n) = (a/n)(b/n).
Multiply on the bottom: (a/mn) = (a/m)(a/n).
Flip: for odd, positive, coprime m and n, (m/n) = (n/m), except when m ≡ n ≡ 3 (mod 4), when (m/n) = −(n/m).
The 2-rule: (2/n) = +1 if n ≡ 1 or 7 (mod 8), and −1 if n ≡ 3 or 5 (mod 8).
The flip is the law of quadratic reciprocity, carried over from primes to every odd number. Reduce, pull out 2s, flip, repeat: the article calls this an efficient O(log a log b) algorithm, analogous to the Euclidean algorithm. You never factor anything but powers of 2.
How do you compute (1001/9907) by hand?
1001 ≡ 1 (mod 4), so flip with no sign change: (1001/9907) = (9907/1001).
Reduce: 9907 = 9 × 1001 + 898, giving (898/1001).
Split the 2: 898 = 2 × 449, and 1001 ≡ 1 (mod 8), so (2/1001) = +1. That leaves (449/1001).
449 ≡ 1 (mod 4): flip to (1001/449), then reduce (1001 = 2 × 449 + 103) to (103/449).
449 ≡ 1 (mod 4): flip to (449/103), then reduce (449 = 4 × 103 + 37) to (37/103).
37 ≡ 1 (mod 4): flip to (103/37), then reduce (103 = 2 × 37 + 29) to (29/37).
29 ≡ 1 (mod 4): flip to (37/29), then reduce to (8/29).
8 = 2³ and 29 ≡ 5 (mod 8), so (2/29) = −1 and (8/29) = (−1)³ = −1.
So (1001/9907) = −1. Check it the slow way: 1001 = 7 × 11 × 13, and the three symbols over 9907 come out as −1, +1 and +1. Trial division by every prime up to 97 shows 9907 is prime, so 1001 is not a square mod 9907, a fact the fast route never needed.
Does (a/n) = 1 mean a is a square mod n?
No, and this is the trap. The Wikipedia article warns that when (a/n) = +1, a may or may not be a quadratic residue mod n: a square mod n must be a square mod every prime factor, but two −1 factors multiply to +1.
Take n = 15. By the 2-rule, (2/3) = −1 and (2/5) = −1, so (2/15) = +1. Yet the squares mod 15 are only 0, 1, 4, 6, 9 and 10; neither 2 nor 8, which also gives +1, is among them. Read the symbol this way:
(a/n) = −1: a is definitely not a square mod n.
(a/n) = 0: a shares a factor with n.
(a/n) = +1 and n prime: a is a square mod n.
(a/n) = +1 and n composite: no conclusion; check each prime factor of n.
How does the Solovay–Strassen test use it?
For a prime p, Euler's criterion says a^((p−1)/2) ≡ (a/p) (mod p). Robert Solovay and Volker Strassen built a primality test on this in a 1977 paper in the SIAM Journal on Computing (DOI 10.1137/0206006). For odd n, pick a random a from 1 to n − 1; if gcd(a, n) > 1, or a^((n−1)/2) mod n differs from (a/n), n is composite. Their abstract states that a prime is always judged correctly, while for composite n the chance of a wrong decision is at most 1/2, and below 2^−m after m independent rounds.
Try n = 15, a = 2: (2/15) = +1, but 2⁷ = 128 ≡ 8 (mod 15), so 15 is composite. The power catches the fake square.
The Wikipedia article on the test credits it with showing the RSA cryptosystem was practical, and says it is largely superseded by the Baillie–PSW and Miller–Rabin tests; Miller–Rabin's failure bound is 4^−k after k rounds. See how the Miller–Rabin primality test works.
How should you practise it?
The Jacobi symbol article gives (19/45) = 1 and (8/21) = −1; work both by the fast route, then check one by factoring. If a rule feels shaky, the Fermi Concept Library covers every concept in mathematics, and the Fermi Problem Library has a step-by-step solver that explains the reasoning.



