TOPICS
Search

Quadratic Nonresidue


A quadratic nonresidue modulo a positive integer p is an integer q for which the congruence

 x^2=q (mod p)

has no integer solution 0<=x<p. If this congruence does have a solution, then q is a quadratic residue (mod p). In particular, 0 is a quadratic residue.

In practice, it suffices to restrict the range to 0<=x<=|_p/2_|, where |_x_| is the floor function, because of the symmetry (p-x)^2=x^2 (mod p).

Triangle of quadratic nonresidues

The following table summarizes the quadratic nonresidues 1<=q<p for small p (OEIS A096013).

pquadratic nonresidues
1(none)
2(none)
32
42, 3
52, 3
62, 5
73, 5, 6
82, 3, 5, 6, 7
92, 3, 5, 6, 8
102, 3, 7, 8
112, 6, 7, 8, 10
122, 3, 5, 6, 7, 8, 10, 11
132, 5, 6, 7, 8, 11
143, 5, 6, 10, 12, 13
152, 3, 5, 7, 8, 11, 12, 13, 14
162, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15
173, 5, 6, 7, 10, 11, 12, 14
182, 3, 5, 6, 8, 11, 12, 14, 15, 17
192, 3, 8, 10, 12, 13, 14, 15, 18
202, 3, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19
QuadraticNonresidueCounts

The numbers of quadratic nonresidues (mod p) for p=1, 2, ... are 0, 0, 1, 2, 2, 2, 3, 5, 5, 4, 5, 8, 6, 6, ... (OEIS A095972).

The smallest quadratic nonresidues for p=3, 4, ... are 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 3, 2, 2, 3, 2, 2, ... (OEIS A020649). For the odd primes p=3, 5, 7, 11, ..., the smallest quadratic nonresidues are 2, 2, 3, 2, 2, 3, 2, 5, 2, 3, 2, 3, ... (OEIS A053760, omitting its initial conventional value 2 for p=2, which has no quadratic nonresidue).

The least quadratic nonresidue modulo a prime number p>3 is less than 3(lnp)^2/2 by the proved generalized Riemann hypothesis for Dirichlet L-functions (Wedeniwski 2001, p. 122; Sutherland 2026).

The following table gives the values of p such that the least quadratic nonresidue is n for small n.

nOEISp such that n is the smallest quadratic nonresidue
2A0250203, 4, 5, 6, 8, 9, 10, 11, 12, 13, 15, ...
3A0250217, 14, 17, 31, 34, 41, 49, 62, 79, 82, ...
5A02502223, 46, 47, 73, 94, 97, 146, 167, 193, ...
7A02502371, 142, 191, 239, 241, 359, 382, ...

Cogentic (2026) reports a deterministic algorithm for finding a quadratic nonresidue modulo an odd prime p in exp(O(sqrt(lnp)lnlnp)) bit time without assuming the generalized Riemann hypothesis. Gemini 4 through Cogentic generated the argument. The public manuscript announces a companion formalization.


See also

Quadratic Residue

Explore with Wolfram|Alpha

References

Sloane, N. J. A. Sequences A020649, A025020, A025021, A025022, A025023, A053760, A095972, and A096013 in "The On-Line Encyclopedia of Integer Sequences."Cogentic. "Unconditional Deterministic Subexponential Integer Factoring and Quadratic Nonresidue Construction." Nov. 25, 2026. https://github.com/google-research/google-research/tree/4a7bc8ab0bc7/cogentic_research_papers/deterministic_factoring_l34.Sutherland, A. V. "Verification Files for the Shorter Lean Proof of RH and of GRH for Dirichlet L-Functions." Updated Nov. 27, 2026. https://math.mit.edu/~drew/shortgrh/.Wedeniwski, S. "Primality Tests on Commutator Curves." PhD thesis. Tübingen, Germany: University of Tübingen, 2001. https://publikationen.uni-tuebingen.de/xmlui/handle/10900/48302.

Referenced on Wolfram|Alpha

Quadratic Nonresidue

Cite this as:

Weisstein, Eric W. "Quadratic Nonresidue." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/QuadraticNonresidue.html

Subject classifications