# 勒让德符号

勒让德符号（Legendre symbol），记作 \( \left(\frac{a}{p}\right) \) 或 \( (a|p) \)，是一个以整数 \( a \) 与奇素数 \( p \) 为自变量的函数：当 \( a \) 是模 \( p \) 的二次剩余（即同余方程 \( x^2 \equiv a \pmod p \) 有解）时取值为 1，无解时取值为 \(-1\)，而当 \( p \) 整除 \( a \) 时取值为 0。<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup><sup> • </sup><sup>[2](https://dlmf.nist.gov/27.9)</sup> 它由阿德里安-马里·勒让德（Adrien-Marie Legendre）引入，把“一个数是否为模某个素数的平方”这一问题转化为一个可以相乘、可以翻转、可以高效计算的代数对象。<sup>[3](https://mathshistory.st-andrews.ac.uk/Miller/mathsym/nth/)</sup>

| 关键事实 | 细节 |
|---|---|
| 取值 | 若 \( p \mid a \) 则为 0；若 \( a \) 是模 \( p \) 的二次剩余则为 1；若 \( a \) 是二次非剩余则为 \(-1\)<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup> |
| 欧拉判别法 | 对奇素数 \( p \)，\( \left(\frac{a}{p}\right) \equiv a^{(p-1)/2} \pmod p \)<sup>[4](https://crypto.stanford.edu/pbc/notes/numbertheory/qr.html)</sup> |
| 乘性 | \( \left(\frac{ab}{p}\right) = \left(\frac{a}{p}\right)\left(\frac{b}{p}\right) \)<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup> |
| 密度 | 模 \( p \) 的非零剩余类中恰有一半是二次剩余<sup>[4](https://crypto.stanford.edu/pbc/notes/numbertheory/qr.html)</sup> |
| 二次互反律 | 对奇素数 \( p, q \)，\( \left(\frac{q}{p}\right) = \left(\frac{p}{q}\right)(-1)^{\left[\frac{p-1}{2}\right]\left[\frac{q-1}{2}\right]} \)<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup> |
| 推广 | 雅可比符号把它推广到奇合数分母；此时雅可比符号为 1 并不保证存在平方根<sup>[5](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln13.html)</sup> |
| 计算代价 | 借助雅可比符号与互反律，求值约需 \( p \) 的位数平方步，且无需分解因数<sup>[6](https://math.gordon.edu/ntic/ntic2017/section-quadratic-reciprocity.html)</sup> |

## 定义与欧拉判别法

对奇素数 \( p \) 与整数 \( a \)，该符号由上述三分支规则定义。<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup> ±1 取值背后的计数是刚性的：在乘法群 \( \mathbb{Z}_p^* \) 中，恰有一半元素是二次剩余，而它们正是某个生成元 \( g \) 的偶次幂。<sup>[4](https://crypto.stanford.edu/pbc/notes/numbertheory/qr.html)</sup>

符号与计算之间的实用桥梁是欧拉判别法：它断言 \( a \) 是二次剩余当且仅当 \( a^{(p-1)/2} \equiv 1 \pmod p \)，是二次非剩余当且仅当 \( a^{(p-1)/2} \equiv -1 \pmod p \)；因此勒让德符号也可直接定义为 \( \left(\frac{a}{p}\right) = a^{(p-1)/2} \)。<sup>[4](https://crypto.stanford.edu/pbc/notes/numbertheory/qr.html)</sup> 证明用到生成元 \( g \)：若 \( a = g^k \) 且 \( k \) 为偶数，则 \( a^{(p-1)/2} = g^{(p-1)m} = 1 \)；而若 \( k \) 为奇数，结果为 \( g^{(p-1)/2} \)，其平方是 \( g^{p-1} = 1 \)，但它本身不可能等于 1，因为 \( g \) 的阶为 \( p-1 \)，故它等于 \(-1\)。<sup>[4](https://crypto.stanford.edu/pbc/notes/numbertheory/qr.html)</sup> 直接作幂运算固然可行，但对大的 \( p \) 计算量沉重，这正是基于互反律的方法之所以重要的原因。<sup>[7](https://docenti.ing.unipi.it/g.dini/Teaching/ssi/materiale-didattico/Basic-cryptography-Asymmetric-encryption-number_theory.pdf)</sup>

## 乘法结构

该符号对分子具有乘性：\( \left(\frac{ab}{p}\right) = \left(\frac{a}{p}\right)\left(\frac{b}{p}\right) \)。<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup> 这由欧拉判别法推出，因为 \( (ab)^{\phi(p)/2} \equiv \left(\frac{a}{p}\right)\left(\frac{b}{p}\right) \pmod p \)。<sup>[8](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Elementary_Number_Theory_%28Raji%29/05%3A_Primitive_Roots_and_Quadratic_Residues/5.05%3A_Legendre_Symbol)</sup> 一个相关的化简是：把 \( a \) 乘以一个平方数不改变符号——对任意与 \( p \) 互素的 \( r \)，有 \( \left(\frac{ar^2}{p}\right) = \left(\frac{a}{p}\right) \)。<sup>[4](https://crypto.stanford.edu/pbc/notes/numbertheory/qr.html)</sup> 作为 \( n \) 的函数，符号 \( (n|p) \) 是模 \( p \) 的一个狄利克雷特征。<sup>[2](https://dlmf.nist.gov/27.9)</sup>

## 特殊值与二次互反律

某些特定的分子有封闭形式（由纳格尔（Nagell）收在其 1951 年的《数论导引》中）：<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup>

\[ \left(\frac{-1}{p}\right) = (-1)^{(p-1)/2}, \qquad \left(\frac{2}{p}\right) = (-1)^{(p^2-1)/8} \]

因此 \(-1\) 是二次剩余当且仅当 \( p \equiv 1 \pmod 4 \)。<sup>[4](https://crypto.stanford.edu/pbc/notes/numbertheory/qr.html)</sup><sup> • </sup><sup>[8](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Elementary_Number_Theory_%28Raji%29/05%3A_Primitive_Roots_and_Quadratic_Residues/5.05%3A_Legendre_Symbol)</sup> 进一步的规则给出：若 \( p \equiv 1 \pmod 6 \) 则 \( \left(\frac{-3}{p}\right) = 1 \)，若 \( p \equiv 5 \pmod 6 \) 则为 \(-1\)；若 \( p \equiv 1, 9 \pmod{10} \) 则 \( \left(\frac{5}{p}\right) = 1 \)，若 \( p \equiv 3, 7 \pmod{10} \) 则为 \(-1\)。<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup>

一般的二次互反律把一个方向上的符号与交换两个素数后的符号联系起来：<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup>

\[ \left(\frac{q}{p}\right) = \left(\frac{p}{q}\right)(-1)^{\left[\frac{p-1}{2}\right]\left[\frac{q-1}{2}\right]} \]

其中 \( p \) 与 \( q \) 为奇素数。在等价的雅可比符号形式 \( \left(\frac{a}{b}\right)\left(\frac{b}{a}\right) = (-1)^{\frac{a-1}{2}\frac{b-1}{2}} \) 下，该定律使计算无需分解因数。<sup>[9](https://crypto.stanford.edu/pbc/notes/numbertheory/quadrecip.html)</sup>

## 计算

按定义求值需要分解因数或作繁重的幂运算，因此高效算法改用互反律。把雅可比符号反复约化——不断析出 2 的幂并通过互反律翻转——会在 \( O(\log n) \) 步内收敛，因为每经过两步，所涉数字就减半。<sup>[10](https://web.ma.utexas.edu/users/voloch/Preprints/algff.pdf)</sup> 以位数计，互反律算法只需约 \( p \) 的位数的平方步，远优于先作因数分解。<sup>[6](https://math.gordon.edu/ntic/ntic2017/section-quadratic-reciprocity.html)</sup> 正是这种多项式时间可计算性，使该符号可用于密码学场景。<sup>[11](https://www.cs.tufts.edu/comp/165/papers/Goldwasser-Bellare-notes-cryptography.pdf)</sup> 当因数分解不可行时，人们退回到欧拉判别法的指数公式。<sup>[12](https://bpb-us-w2.wpmucdn.com/sites.uml.edu/dist/e/98/files/2020/03/Klain_Essentials-of-Number-Theory.pdf)</sup>

一个演算示例展示了“翻转再约化”的模式：\( \left(\frac{31}{103}\right) = -\left(\frac{103}{31}\right) = -\left(\frac{-21}{31}\right) = \cdots = \left(\frac{-1}{11}\right) = -1 \)，故 31 是模 103 的二次非剩余。<sup>[9](https://crypto.stanford.edu/pbc/notes/numbertheory/quadrecip.html)</sup>

## 雅可比符号与密码学用途

雅可比符号 \( \left(\frac{a}{n}\right) \) 把勒让德符号推广到任意奇正整数分母 \( n \)（其素因数分解为 \( n = p_1^{e_1} \cdots p_k^{e_k} \)），定义为乘积 \( \left(\frac{a}{p_1}\right)^{e_1} \cdots \left(\frac{a}{p_k}\right)^{e_k} \)；当 \( n \) 为单个奇素数时，两种符号一致。<sup>[5](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln13.html)</sup><sup> • </sup><sup>[9](https://crypto.stanford.edu/pbc/notes/numbertheory/quadrecip.html)</sup> 这一推广失去了一条性质：\( \left(\frac{a}{n}\right) = -1 \) 可证明 \( a \) 不是模 \( n \) 的二次剩余，但取值为 1 并不保证存在平方根。对 \( n = pq \)（\( p, q \) 为互异的奇素数），当 \( a \) 同时是模两个素数的剩余时取值为 1，当它同时是模两个素数的非剩余时也取值为 1；后一类数称为伪平方数。<sup>[5](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln13.html)</sup>

雅可比符号出现在素性检验中。在索洛韦–斯特拉森检验（Solovay–Strassen test）中，人们对随机的 \( d \) 检验是否有 \( d^{(n-1)/2} \equiv \left(\frac{d}{n}\right) \pmod n \)；当 \( n \) 为奇合数时，通过该检验的 \( d \) 构成一个真子群，因此至少有一半候选者会暴露其合数性，这使该检验成为一种概率多项式时间的素性检验。<sup>[10](https://web.ma.utexas.edu/users/voloch/Preprints/algff.pdf)</sup> 判定模合数 \( n \) 的二次剩余性同样与因数分解相关联：一个高效的模 \( n \) 剩余性检验将能高效统计 \( \mathbb{Z}_n^* \) 中剩余所占的比例，从而给出一种高效方法来判断 \( n \) 有两个还是三个互异的素因子。<sup>[7](https://docenti.ing.unipi.it/g.dini/Teaching/ssi/materiale-didattico/Basic-cryptography-Asymmetric-encryption-number_theory.pdf)</sup>

## 历史

勒让德在 1798 年首次出版的《数论随笔》（*Essai sur la théorie des nombres*）中引入了这一符号；他早在 1785 年的一篇论文中就已陈述互反律，但当时尚无此符号。<sup>[3](https://mathshistory.st-andrews.ac.uk/Miller/mathsym/nth/)</sup> 1911 年《大英百科全书》（*Encyclopædia Britannica*）的记述与此相符：符号 \( (a/p) \) 未见于 1785 年的论文，而是首次用于《数论随笔》。<sup>[13](https://en.wikisource.org/wiki/Page%3AEB1911_-_Volume_16.djvu/395)</sup> 二次互反律本身并非由勒让德最早陈述：它出现在欧拉（Euler）1751 年的著作中，1783 年再度出现，不过两项相关成果——互反律与等差数列中的素数——的功绩仍主要归于勒让德。<sup>[14](https://mathshistory.st-andrews.ac.uk/Biographies/Legendre/)</sup> 勒让德自己的证明尝试并不完整；高斯（Gauss）在批评了勒让德 1785 年的证明及 1798 年改进版之后，于 1801 年给出了该定律的第一个证明，勒让德则在 1808 年版《数论》（*Théorie des nombres*）中采用了高斯的证明并给予了应有的致谢。<sup>[14](https://mathshistory.st-andrews.ac.uk/Biographies/Legendre/)</sup> 勒让德确实确立了该符号是良定义且具有乘性的，而这一性质欧拉早已注意到。<sup>[15](https://www.treccani.it/enciclopedia/l-eta-dei-lumi-matematica-la-teoria-dei-numeri_%28Storia-della-Scienza%29/)</sup>

## 相关符号

当分母为奇素数时，雅可比符号退化为勒让德符号；在 Wolfram 语言中，勒让德符号通过 `JacobiSymbol[a, p]` 实现。<sup>[1](https://mathworld.wolfram.com/LegendreSymbol.html)</sup>

## References

1. [Weisstein, Eric W. "Legendre Symbol." MathWorld--A Wolfram Resource.](https://mathworld.wolfram.com/LegendreSymbol.html)
2. [DLMF §27.9 Quadratic Characters, NIST Digital Library of Mathematical Functions.](https://dlmf.nist.gov/27.9)
3. [Earliest Uses of Symbols of Number Theory, MacTutor History of Mathematics.](https://mathshistory.st-andrews.ac.uk/Miller/mathsym/nth/)
4. [Number Theory notes: Quadratic Residues, Stanford cryptography notes (P. B. notes).](https://crypto.stanford.edu/pbc/notes/numbertheory/qr.html)
5. [Lecture 13: Jacobi Symbol, Yale CS 467 course notes (2006).](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln13.html)
6. [NTIC: Quadratic Reciprocity, Gordon College.](https://math.gordon.edu/ntic/ntic2017/section-quadratic-reciprocity.html)
7. [Modern Cryptography: Theory and Practice, course text (University of Pisa mirror).](https://docenti.ing.unipi.it/g.dini/Teaching/ssi/materiale-didattico/Basic-cryptography-Asymmetric-encryption-number_theory.pdf)
8. [5.5: Legendre Symbol, Elementary Number Theory (Raji), Mathematics LibreTexts.](https://math.libretexts.org/Bookshelves/Combinatorics_and_Discrete_Mathematics/Elementary_Number_Theory_%28Raji%29/05%3A_Primitive_Roots_and_Quadratic_Residues/5.05%3A_Legendre_Symbol)
9. [Number Theory notes: Quadratic Reciprocity, Stanford cryptography notes.](https://crypto.stanford.edu/pbc/notes/numbertheory/quadrecip.html)
10. [Algorithms for Finite Fields (Völoch), University of Texas at Austin.](https://web.ma.utexas.edu/users/voloch/Preprints/algff.pdf)
11. [Goldwasser and Bellare, Cryptography Lecture Notes, Tufts University.](https://www.cs.tufts.edu/comp/165/papers/Goldwasser-Bellare-notes-cryptography.pdf)
12. [Klain, Essentials of Number Theory, University of Massachusetts Lowell.](https://bpb-us-w2.wpmucdn.com/sites.uml.edu/dist/e/98/files/2020/03/Klain_Essentials-of-Number-Theory.pdf)
13. [Encyclopædia Britannica, 11th ed., Vol. 16, "Legendre" (Wikisource page scan).](https://en.wikisource.org/wiki/Page%3AEB1911_-_Volume_16.djvu/395)
14. [Adrien-Marie Legendre (1752–1833), MacTutor History of Mathematics.](https://mathshistory.st-andrews.ac.uk/Biographies/Legendre/)
15. [L'età dei lumi: la teoria dei numeri, Treccani, Storia della Scienza.](https://www.treccani.it/enciclopedia/l-eta-dei-lumi-matematica-la-teoria-dei-numeri_%28Storia-della-Scienza%29/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Number theory › Elementary number theory › Quadratic residues and reciprocity

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/legendre-symbol

English original: https://www.edgepedia.org/legendre-symbol
