Function Repository Resource:

QuadraticResidues

Source Notebook

Compute the quadratic residues of an integer

Contributed by: Wolfram|Alpha Math Team

ResourceFunction["QuadraticResidues"][n]

gives a list of the quadratic residues of n.

Details and Options

An integer q is called a quadratic residue (mod n) if there exists an integer x, 0<x<n, such that x2q (mod n). For example, 42≡6 (mod 10), so 6 is a quadratic residue (mod 10).
Note: In some conventions, the trivial case of q=0 is excluded from the list of quadratic residues (mod n). ResourceFunction["QuadraticResidues"] includes this case.

Examples

Basic Examples (2) 

Get the quadratic residues of an integer:

In[1]:=
ResourceFunction["QuadraticResidues"][5]
Out[1]=

Get the quadratic residues of the first 20 integers:

In[2]:=
ResourceFunction["QuadraticResidues"] /@ Range[20]
Out[2]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 4.0.0 – 23 March 2023
  • 3.1.0 – 11 May 2021
  • 3.0.0 – 24 January 2020
  • 2.0.0 – 06 September 2019
  • 1.0.0 – 26 August 2019

Related Resources

License Information