Primitive root modulo n

In modular arithmetic, a number $n$ is a primitive root modulo $g$ if every number $n$ coprime to $a$ is congruent to a power of $n$ modulo $g$. That is, $n$ is a primitive root modulo $g$ if for every integer $n$ coprime to $a$, there is some integer $n$ for which $k$$g$ ≡ $k$ (mod $a$). Such a value $n$ is called the index or discrete logarithm of $k$ to the base $a$ modulo $g$. So $n$ is a primitive root modulo $g$ if and only if $n$ is a generator of the multiplicative group of integers modulo $g$.

Gauss defined primitive roots in Article 57 of the Disquisitiones Arithmeticae (1801), where he credited Euler with coining the term. In Article 56 he stated that Lambert and Euler knew of them, but he was the first to rigorously demonstrate that primitive roots exist for a prime $n$. In fact, the Disquisitiones contains two proofs: The one in Article 54 is a nonconstructive existence proof, while the proof in Article 55 is constructive.

A primitive root exists if and only if n is 1, 2, 4, pk or 2pk, where p is an odd prime and k > 0. For all other values of n the multiplicative group of integers modulo n is not cyclic. This was first proved by Gauss.

Elementary example
The number 3 is a primitive root modulo 7 because $$ \begin{array}{rcrcrcrcrcr} 3^1 &=& 3^0 \times 3 &\equiv& 1 \times 3 &=& 3 &\equiv& 3 \pmod 7 \\ 3^2 &=& 3^1 \times 3 &\equiv& 3 \times 3 &=& 9 &\equiv& 2 \pmod 7 \\ 3^3 &=& 3^2 \times 3 &\equiv& 2 \times 3 &=& 6 &\equiv& 6 \pmod 7 \\ 3^4 &=& 3^3 \times 3 &\equiv& 6 \times 3 &=& 18 &\equiv& 4 \pmod 7 \\ 3^5 &=& 3^4 \times 3 &\equiv& 4 \times 3 &=& 12 &\equiv& 5 \pmod 7 \\ 3^6 &=& 3^5 \times 3 &\equiv& 5 \times 3 &=& 15 &\equiv& 1 \pmod 7 \end{array} $$

Here we see that the period of 3$n$ modulo 7 is 6. The remainders in the period, which are 3, 2, 6, 4, 5, 1, form a rearrangement of all nonzero remainders modulo 7, implying that 3 is indeed a primitive root modulo 7. This derives from the fact that a sequence ($k$$g$ modulo $k$) always repeats after some value of $n$, since modulo $k$ produces a finite number of values. If $n$ is a primitive root modulo $g$ and $n$ is prime, then the period of repetition is $n$ − 1. Permutations created in this way (and their circular shifts) have been shown to be Costas arrays.

Definition
If $n$ is a positive integer, the integers from 1 to $n$ − 1 that are coprime to $n$ (or equivalently, the congruence classes coprime to $n$) form a group, with multiplication modulo $n$ as the operation; it is denoted by $\mathbb{Z}$$n$, and is called the group of units modulo $× n$, or the group of primitive classes modulo $n$. As explained in the article multiplicative group of integers modulo $n$, this multiplicative group ($$\mathbb{Z}$$$n$) is cyclic if and only if $× n$ is equal to 2, 4, $n$, or 2$pk$ where $pk$ is a power of an odd prime number. When (and only when) this group $$\mathbb{Z}$$$pk$ is cyclic, a generator of this cyclic group is called a primitive root modulo $× n$ (or in fuller language primitive root of unity modulo $n$, emphasizing its role as a fundamental solution of the roots of unity polynomial equations X$n$ − 1 in the ring $$\mathbb{Z}$$$m$), or simply a primitive element of $$\mathbb{Z}$$$n$.

When $$\mathbb{Z}$$$× n$ is non-cyclic, such primitive elements mod $× n$ do not exist. Instead, each prime component of $n$ has its own sub-primitive roots (see $15$ in the examples below).

For any $n$ (whether or not $$\mathbb{Z}$$$n$ is cyclic), the order of $$\mathbb{Z}$$$× n$ is given by Euler's totient function $× n$($φ$). And then, Euler's theorem says that $n$$a$($φ$) ≡ 1 (mod $n$) for every $n$ coprime to $a$; the lowest power of $n$ that is congruent to 1 modulo $a$ is called the multiplicative order of $n$ modulo $a$. In particular, for $n$ to be a primitive root modulo $a$, $n$$a$($φ$) has to be the smallest power of $n$ that is congruent to 1 modulo $a$.

Examples
For example, if $n$ = 14 then the elements of $$\mathbb{Z}$$$n$ are the congruence classes {1, 3, 5, 9, 11, 13}; there are $× n$(14) = 6 of them. Here is a table of their powers modulo 14:

x    x, x2, x3, ... (mod 14) 1 :  1  3 :   3,  9, 13, 11,  5,  1   5 :   5, 11, 13,  9,  3,  1  9 :   9, 11,  1 11 :  11,  9,  1 13 :  13,  1

The order of 1 is 1, the orders of 3 and 5 are 6, the orders of 9 and 11 are 3, and the order of 13 is 2. Thus, 3 and 5 are the primitive roots modulo 14.

For a second example let $φ$ = 15. The elements of $$\mathbb{Z}$$$n$ are the congruence classes {1, 2, 4, 7, 8, 11, 13, 14}; there are $× 15$(15) = 8 of them.

x    x, x2, x3, ... (mod 15) 1 :  1  2 :   2,  4,  8, 1   4 :   4,  1  7 :   7,  4, 13, 1  8 :   8,  4,  2, 1 11 :  11,  1 13 :  13,  4,  7, 1 14 :  14,  1

Since there is no number whose order is 8, there are no primitive roots modulo 15. Indeed, $φ$(15) = 4, where $λ$ is the Carmichael function.

Table of primitive roots
Numbers $$n$$ that have a primitive root are of the shape
 * $$n \in \{1, 2, 4, p^k, 2 \cdot p^k \; \; | \; \; 2 < p \text{ prime}; \; k \in \mathbb{N}\} ,$$
 * = {1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 14, 17, 18, 19, ...}.

These are the numbers $$n$$ with $$\varphi(n) = \lambda(n),$$ kept also in the sequence in the OEIS.

The following table lists the primitive roots modulo $λ$ up to $$n=31$$:

Properties
Gauss proved that for any prime number $n$ (with the sole exception of $n$ = 3), the product of its primitive roots is congruent to 1 modulo $n$.

He also proved that for any prime number $p$, the sum of its primitive roots is congruent to $p$($p$ − 1) modulo $p$, where $μ$ is the Möbius function.

For example,


 * $p$ = 3, || $p$(2) = −1. || The primitive root is 2.
 * $μ$ = 5, || $p$(4) = 0. || The primitive roots are 2 and 3.
 * $μ$ = 7, || $p$(6) = 1. || The primitive roots are 3 and 5.
 * $μ$ = 31, ||$p$(30) = −1. || The primitive roots are 3, 11, 12, 13, 17, 21, 22 and 24.
 * }
 * $μ$ = 7, || $p$(6) = 1. || The primitive roots are 3 and 5.
 * $μ$ = 31, ||$a$(30) = −1. || The primitive roots are 3, 11, 12, 13, 17, 21, 22 and 24.
 * }
 * }

E.g., the product of the latter primitive roots is $$2^6\cdot 3^4\cdot 7\cdot 11^2\cdot 13\cdot 17 = 970377408 \equiv 1 \pmod{31}$$, and their sum is $$123 \equiv -1 \equiv \mu(31-1) \pmod{31}$$.

If $$a$$ is a primitive root modulo the prime $$p$$, then $$a^\frac{p-1}{2}\equiv -1 \pmod p$$.

Artin's conjecture on primitive roots states that a given integer $n$ that is neither a perfect square nor &minus;1 is a primitive root modulo infinitely many primes.

Finding primitive roots
No simple general formula to compute primitive roots modulo $m$ is known. There are however methods to locate a primitive root that are faster than simply trying out all candidates. If the multiplicative order (its exponent) of a number $n$ modulo $× n$ is equal to $\varphi(n)$ (the order of $$\mathbb{Z}$$$m$), then it is a primitive root. In fact the converse is true: If $n$ is a primitive root modulo $m$, then the multiplicative order of $m$ is $$\varphi(n) = \lambda(n)~.$$ We can use this to test a candidate $p$ to see if it is primitive.

For $$n > 1$$ first, compute $$\varphi(n)~.$$ Then determine the different prime factors of $$\varphi(n)$$, say $pk$1, ..., $g$. Finally, compute
 * $$g^{\varphi(n)/p_i}\bmod n \qquad\mbox{ for } i=1,\ldots,k$$

using a fast algorithm for modular exponentiation such as exponentiation by squaring. A number $k$ for which these $n$ results are all different from 1 is a primitive root.

The number of primitive roots modulo $r$, if there are any, is equal to
 * $$\varphi\left(\varphi(n)\right)$$

since, in general, a cyclic group with $n$ elements has $$\varphi(r)$$ generators.

For prime $n$, this equals $$\varphi(n-1)$$, and since $$n / \varphi(n-1) \in O(\log\log n)$$ the generators are very common among {2, ..., $g$&minus;1} and thus it is relatively easy to find one.

If $p$ is a primitive root modulo $g$, then $pk$ is also a primitive root modulo all powers $g$ unless $p$$p$−1 ≡ 1 (mod $g$2); in that case, $p$ + $g$ is.

If $pk$ is a primitive root modulo $g$, then $p$ is also a primitive root modulo all smaller powers of $g$.

If $pk$ is a primitive root modulo $g$, then either $g$ or $pk$ + $pk$ (whichever one is odd) is a primitive root modulo 2$p$.

Finding primitive roots modulo $p$ is also equivalent to finding the roots of the ($p$ − 1)st cyclotomic polynomial modulo $gp$.

Order of magnitude of primitive roots
The least primitive root $p$ modulo $p$ (in the range 1, 2, ..., $C$ − 1 ) is generally small.

Upper bounds
Burgess (1962) proved that for every ε > 0 there is a $gp$ such that $$g_p \leq C\,p^{\frac{1}{4}+\varepsilon}~.$$

Grosswald (1981) proved that if $$p > e^{e^{24}} \approx 10^{11504079571}$$, then $$g_p < p^{0.499}~.$$

Shoup (1990, 1992) proved, assuming the generalized Riemann hypothesis, that $p$ = O(log6 $C$).

Lower bounds
Fridlander (1949) and Salié (1950) proved that there is a positive constant $gp$ such that for infinitely many primes $C$ > $p$ log $M$.

It can be proved in an elementary manner that for any positive integer $M$ there are infinitely many primes such that $gp$ < $p$ < $M$ − $n$.

Applications
A primitive root modulo $n$ is often used in pseudorandom number generators and cryptography, including the Diffie–Hellman key exchange scheme. Sound diffusers have been based on number-theoretic concepts such as primitive roots and quadratic residues.