Prerequisites: Fermat's little theorem, Euler's theorem, and Lagrange's theorem
Order and primitive roots are important tools for understanding the multiplicative structure of the reduced residue system modulo , . They provide a basis for defining concepts such as the discrete logarithm. More general discussions can be found in the relevant sections on group theory and ring theory in abstract algebra.
Order
Throughout this section, assume that the modulus and the base are coprime, that is, , also written as .
For , the powers exhibit a cyclic structure. The minimum length of this cycle is the order of modulo . The order is defined as the exponent at which the power first returns to its starting point :
Order
For with , the smallest positive integer satisfying , namely , is called modulo 's order (the order of modulo ), denoted by or .
Note
In abstract algebra, the “order” here is the order of the element in the group formed by the reduced residue system modulo under multiplication, where that element is . The notation for order is specific to this particular group. Many of the properties below generalize directly to the properties of the order of a group element in abstract algebra.
There is also the concept of “half-order”, denoted by in number theory. It is the smallest positive integer satisfying . Half-order is not a group-theoretic concept. An order always exists, whereas a half-order need not.
Cyclic structure of powers
The order can be used to characterize the cyclic structure of powers. For , divide the exponent by the order with remainder:
Then, using the laws of exponents, we obtain
This shows that a power with any exponent can be shifted into the first nonnegative cycle. From this, we obtain a series of properties of order.
Property 1
For with , the powers are pairwise incongruent modulo .
Proof
Consider a proof by contradiction. Suppose there exist two numbers such that . Then . However, , contradicting the minimality of the order. Thus the proposition holds.
Property 2
For with , the congruence holds if and only if .
Proof
As stated above, . By Property 1, among the unique value for which holds is , namely . Therefore, if and only if , that is, .
In Euler's theorem, the congruence holds for every . Combined with Property 2, this means that for every , . In other words, is a common multiple of the orders of all . For a positive integer , the least common multiple of all orders is denoted by ; it is the Carmichael function of . Its properties will be discussed in detail below.
As with other cyclic structures, from the order of we can calculate the order of .
Property 3
For with , we have
Proof
By Property 2, the congruence holds if and only if . This condition is equivalent to
The smallest positive integer satisfying this condition is
Order of a product
Let be distinct integers coprime to . If the orders and are known, then we can likewise obtain information about the order of their product , denoted by .
Property 4
For with , we have
Proof
Since is a multiple of both and , Property 2 gives
Applying Property 2 again gives
This proves the divisibility relation on the right.
Conversely,
so Property 2 gives . Canceling from both sides yields
After canceling the common factor, the two fractions are coprime, so
Similarly,
Since the left-hand sides of these two divisibility relations are coprime,
This proves the divisibility relation on the left.
When the orders of and are coprime, this conclusion takes a simpler form.
Property 4'
For with , we have
Proof
If , then all the divisibility relations in Property 4 are equalities, so
Conversely, if , then Property 4 gives
This immediately implies , namely .
In general, the bounds obtained in Property 4 are tight. The lower bound for the order of a product is easy to attain: for example, when , , but the order of their product is .
Although the order of the product is not necessarily the least common multiple of their orders in general, it is always possible to find an element whose order equals this least common multiple.
Property 5
For with , there always exists with such that
Proof
Consider the prime factorizations:
According to the relative sizes of and , divide all prime factors into two classes:
Define
so that and . By Property 3,
Since , Property 4' gives
Therefore, is an element whose order is .
This conclusion is often used to construct an element of a prescribed order.
Primitive roots
Primitive roots are special elements whose order equals the number of elements in the reduced residue system modulo .
Primitive root
For , if there exists with such that , then is called a primitive root modulo (primitive root modulo ). Here, is the Euler totient function.
Not every positive integer has a primitive root modulo . By Property 1 above, if a primitive root modulo , denoted by , exists, then the congruence classes containing are all distinct and form the reduced residue system modulo . In particular, for a prime , the residues are pairwise distinct for .
Note
In abstract algebra, a primitive root is a generator of a cyclic group. The name “primitive root” is used only for the group formed by the reduced residue system modulo under multiplication; in a general cyclic group, the term “generator” is used. The group formed by the reduced residue system modulo under multiplication is not always cyclic: the existence of a primitive root means that it is isomorphic to a cyclic group, while the absence of a primitive root means that it is not.
When the modulus is , the multiplicative group of integers modulo is . This is clearly a cyclic group, so its primitive root is .
Primitive-root criterion
If all prime factors of are known, it is easy to determine whether a primitive root modulo exists.
Theorem
For an integer and , is a primitive root modulo if and only if, for every prime factor of , denoted by ,
Proof
Necessity is clear. To prove sufficiency, use a proof by contradiction. If is not a primitive root modulo , then . By Property 2 and Euler's theorem, . Let be a prime factor of ; then . Applying Property 2 again gives
But is also a factor of , contradicting the hypothesis. Thus sufficiency holds.
Number of primitive roots
A primitive root, if it exists, need not be unique. In general, the possible orders of elements in the reduced residue system modulo , and the number of elements of each order, satisfy the following theorem:
Theorem
If a positive integer has a primitive root , then, when , an element modulo of order exists, and there are exactly such elements. In particular, the number of primitive roots modulo is .
Proof
By the definition of a primitive root, every reduced residue class modulo can be written as , where is one of . By Property 3, the orders of these elements are
Therefore, an element of order exists if and only if . For , let . The set of these elements is
The corresponding values are precisely the positive integers no greater than and coprime to . By the definition of the Euler totient function, there are of them.
Primitive-root existence theorem
This section establishes the following primitive-root existence theorem:
Theorem
A primitive root modulo exists if and only if , where is an odd prime and .
To explain this result, consider the following four cases:
-
For , primitive roots are respectively , so they clearly exist.
-
is a power of an odd prime, where is an odd prime and .
???+ note "Lemma 1" For an odd prime , a primitive root modulo exists.
??? note "Proof" The proof has two steps.
**Step 1**: For $d\mid(p-1)$, the congruence $x^d\equiv 1\pmod p$ has exactly $d$ distinct solutions. Let $p-1=kd$, and consider the polynomial $$ f(x) = x^{d(k-1)} + x^{d(k-2)} + \cdots + x^d + 1. $$ By [Euler's theorem](/knowledge-pages/math-number-theory-fermat#欧拉定理), the congruence $(x^d-1)f(x)=x^{p-1}-1\equiv 0\pmod{p}$ has exactly $p-1$ distinct solutions. These solutions are zeros of $x^d-1$ and $f(x)$ respectively. By [Lagrange's theorem](/knowledge-pages/math-number-theory-congruence-equation#定理-3lagrange-定理), they can have at most $d$ and $d(k-1)$ distinct zeros, respectively. Since $d+d(k-1)=p-1$, the former must have exactly $d$ distinct zeros. Thus $x^d\equiv 1\pmod p$ has exactly $d$ distinct solutions. **Step 2**: For $d\mid(p-1)$, the elements of order $d$ number exactly $\varphi(d)$. Sort all divisors of $\varphi(p)$, and then use induction. Since the only element of order $1$ is $1$, the base case holds. For $d\mid(p-1)$, by [Property 2](#ord-prop-2), every solution of $x^d\equiv 1\pmod p$ satisfies $\delta_p(x)\mid d$. Therefore, the number of elements of order $d$ is $$ N(d) = d - \sum_{e\mid d,~e\neq d} N(e) = d - \sum_{e\mid d,~e\neq d} \varphi(e) = \varphi(d). $$ The second equality is the induction hypothesis, and the third is a property of the Euler totient function. By mathematical induction, for every $d\mid(p-1)$ there are exactly $\varphi(d)$ elements of order $d$. In particular, for $d=p-1$, there are exactly $\varphi(p-1)$ elements of order $(p-1)$. Therefore, a primitive root modulo $p$ exists.???+ note "Lemma 2" For an odd prime and , a primitive root modulo exists.
??? note "Proof" The proof has three steps.
**Step 1**: There exists a primitive root modulo $p$, denoted by $g$, such that $g^{p-1}\not\equiv 1\pmod{p^2}$. Take any primitive root modulo $p$, denoted by $g$. If it does not satisfy the condition, namely if $g^{p-1}\equiv 1\pmod{p^2}$, then one can show that $g+p$ does satisfy it: $g+p$ is also a primitive root modulo $p$, and $$ \begin{aligned} (g+p)^{p-1} &\equiv \binom{p-1}{0}g^{p-1} + \binom{p-1}{1}g^{p-2}p \\ &= g^{p-1} + g^{p-2}p(p-1) \\ &\equiv 1 - pg^{p-2} \not\equiv 1 \pmod{p^2}. \end{aligned} $$ **Step 2**: For the $g$ chosen above and every $e\ge 1$, $g^{\varphi(p^e)}\not\equiv 1\pmod{p^{e+1}}$. The choice of $g$ ensures that this holds for $e=1$. Assume it holds for $e$; we prove it for $e+1$. For any $e \ge 1$, Euler's theorem gives a $\lambda$ such that $$ g^{\varphi(p^e)} = 1 + \lambda p^e $$ holds. By the induction hypothesis, $\lambda\perp p$. Since $\varphi(p^{e+1})=p\varphi(p^e)$, $$ g^{\varphi(p^{e+1})} = \left(g^{\varphi(p^{e})}\right)^p = (1 + \lambda p^e)^p \equiv 1 + \lambda p^{e+1} \pmod{p^{e+2}}. $$ Together with $\lambda\perp p$, this shows that $g^{\varphi(p^{e+1})}\not\equiv 1\pmod{p^{e+2}}$. The claim follows by induction. **Step 3**: The chosen $g$, for every $e\ge 1$, is a primitive root modulo $p^e$. The choice of $g$ ensures the claim for $e=1$. Assume it holds for $e$; we prove it for $e+1$. Abbreviate $\delta_{p^{e+1}}(g)$ as $\delta$. Since $g^\delta\equiv 1\pmod{p^{e+1}}$, we also have $g^\delta\equiv 1\pmod{p^e}$. By the induction hypothesis, $\delta_{p^e}(g) = \varphi(p^e)$. Therefore, by [Property 2](#ord-prop-2), $\varphi(p^e)\mid\delta$. Euler's theorem also gives $\delta\mid\varphi(p^{e+1})$. But $\varphi(p^{e+1})=p\varphi(p^e)$, so there are only two possibilities: $\delta=\varphi(p^e)$ or $\delta=\varphi(p^{e+1})$. The conclusion of Step 2 says that $g^{\varphi(p^e)}\not\equiv 1\pmod{p^{e+1}}$, so the possibility $\delta=\varphi(p^e)$ does not hold. The only possibility is $\delta=\varphi(p^{e+1})$. Thus $g$ is a primitive root modulo $p^{e+1}$. The claim follows for every $e\ge 1$ by induction. -
, where is an odd prime and .
???+ note "Lemma 3" For an odd prime and , a primitive root modulo exists.
??? note "Proof" Let be a primitive root modulo . Then is also a primitive root modulo . Exactly one of the two is odd; assume without loss of generality that it is . Clearly, . Let ; we need to prove that . Euler's theorem gives . On the other hand, by definition , so . Thus, by Property 2 and the choice of , . From the formula for the Euler totient function, . Hence, , showing that is the order of a primitive root modulo .
-
, where is an odd prime and .
???+ note "Lemma 4" Suppose and there are no odd prime and positive integer such that or . Then no primitive root modulo exists.
??? note "Proof" For with , suppose that modulo there exists a primitive root . Since , it must be odd. Write with . Then
$$ \begin{aligned} g^{2^{e-2}} &=(2k+1)^{2^{e-2}} \\ &\equiv 1 + \binom{2^{e-2}}{1}(2k) + \binom{{2^{e-2}}}{2}(2k)^2 \\ &= 1 + 2^{e-1}k + 2^{e-1}(2^{e-2}-1)k^2 \\ &= 1 + 2^{e-1}(k + (2^{e-2}-1)k^2) \\ &\equiv 1 \pmod{2^{e}}. \end{aligned} $$ In the penultimate line, $k$ and $(2^{e-2}-1)k^2$ have the same parity, so their sum is even. By the definition of order, $\delta_{2^{e}}(g)\le 2^{e-2}< \varphi(2^{e}) = 2^{e-1}$, contradicting the assumption that $g$ is a primitive root. Thus no such primitive root exists. Now suppose that $m$ satisfies the stated conditions but is not a power of $2$. Then there must exist $2 < m_1 < m_2$ with $m_1\perp m_2$ such that $m=m_1m_2$. Suppose that a primitive root modulo $m$, denoted by $g$, exists. Since $g\perp m$, for $i=1,2$ we have $g\perp m_i$. Euler's theorem gives $$ g^{\varphi(m_i)} \equiv 1 \pmod{m_i}. $$ Since $m_i > 2$, $\varphi(m_i)$ is even, so for $i=1,2$, $$ g^{\frac{1}{2}\varphi(m_1)\varphi(m_2)} \equiv 1 \pmod{m_i}. $$ By the [Chinese remainder theorem](/knowledge-pages/math-number-theory-crt), $$ g^{\frac{1}{2}\varphi(m_1)\varphi(m_2)} \equiv 1 \pmod{m}. $$ Since $\varphi(m)=\varphi(m_1)\varphi(m_2)$, the definition of order gives $$ \delta_m(g) \le \frac{1}{2}\varphi(m_1)\varphi(m_2) = \dfrac{1}{2}\varphi(m) < \varphi(m). $$ This contradicts the assumption that $g$ is a primitive root modulo $m$. Therefore, by contradiction, no primitive root modulo $m$ exists.
Combining these four lemmas gives the necessary and sufficient condition for a number to have a primitive root.
Algorithm for finding a primitive root
For any modulus that has a primitive root, finding a primitive root only requires enumerating possible positive integers and checking them one by one. There are usually two ways to enumerate them: enumerate in increasing order, or generate positive integers at random. These two approaches have comparable practical efficiency.
Enumerating in increasing order yields the smallest primitive root modulo , denoted by . Therefore, the complexity of the enumeration depends on the size of . The following estimates are known:
- Upper bound: Wang1 and Burgess2 proved that the least primitive root of a prime satisfies , where . Cohen, Odoni, and Stothers3 and Elliott and Murata4 proved that this estimate also holds for the moduli and , respectively, where is an odd prime. Since for , a primitive root modulo (or ) is also a primitive root modulo (or ), the upper bound for the least primitive root holds in all cases.
- Lower bound: Fridlander5 and Salié6 proved that there is a such that, for infinitely many primes , the least primitive root satisfies .
- Average case: Burgess and Elliott7 proved that, on average, the least primitive root of a prime satisfies . Elliott and Murata8 further conjectured that the average value of the least primitive root of a prime is a constant, and numerical verification9 suggests that it is approximately . Elliott and Murata4 later extended this conjecture to the case of the modulus .
According to these estimates, when the least primitive root is sought by brute force, the enumeration complexity is acceptable.
In addition to enumerating in increasing order, one can search for a primitive root by randomly generating positive integers and checking them. Primitive roots are not particularly sparse:10
Therefore, when the random method is used, the expected complexity of the enumeration is .
It should be noted that testing whether an integer is a primitive root requires the prime factorization of . Among the common prime-factorization algorithms in programming contests, even the asymptotically fastest Pollard Rho algorithm requires time. Thus, whenever the prime factorization of is unknown, the bottleneck in finding a primitive root, regardless of the enumeration method, is factorization rather than enumeration and verification.
Carmichael function
In contrast to the local concept of the order of an element modulo , the Carmichael function is a global concept. It is the least common cycle length of the powers of all integers coprime to .
Carmichael function
For , define to be the smallest positive integer satisfying for every ; this integer is . The function is called the Carmichael function.
By Property 2, having for every means that for every . In other words, every positive integer satisfying this condition is a common multiple of all the . Therefore, the smallest such is their least common multiple:
This is also commonly used as an equivalent definition of the Carmichael function.
Repeated application of Property 5 shows that there is always an element with . Therefore, the formula can also be written as
The element attaining this maximum is also called a primitive root modulo with -order. Such an element exists for every modulus .
Recurrence formula
The Carmichael function is an arithmetic function. This section discusses one of its recurrence formulas and uses it to give another proof of the primitive-root existence theorem.
Although it is not a multiplicative function, the Carmichael function can likewise be computed by handling coprime factors separately.
Lemma
For coprime positive integers , .
Proof
Let and be primitive roots modulo and , respectively, attaining the corresponding values. Let . By the Chinese remainder theorem, there is an such that for . Since , for , we have . Thus, by Property 2 and the choice of , . Hence .
Conversely, for every and , . Applying the Chinese remainder theorem gives for every . By the definition of the Carmichael function, .
Thus the equality in the lemma holds.
It remains to calculate the value of the Carmichael function at prime powers. First consider powers of .
Lemma
For with , , , and for every , .
Proof
For , the cases can be handled separately. For with , repeat the first part of the proof of Lemma 4 above to obtain . It remains to prove that an element of order exists. For this,
This shows that . Since , must be an element of order . Hence .
The proof of this lemma in fact gives a description of the structure of the reduced residue system modulo :
Corollary
Let the modulus be with . Then every odd integer is congruent to a unique integer of the form , where and . In other words, are pairwise incongruent and form a reduced residue system.
Proof
The case is easy to verify. For , the proof above has already shown that the order of modulo is , so are pairwise incongruent. Since these integers are all congruent modulo to , while their negatives are congruent modulo to , the numbers are pairwise incongruent modulo . There are of them, exactly the size of the reduced residue system modulo , so they form the reduced residue system itself.
Next consider odd prime powers.
Lemma
For , where is an odd prime and , .
Proof
First prove the claim for , namely for the case where is an odd prime. By the definition of the Carmichael function, all integers coprime to , denoted by , are solutions of . In the sense of modulo , this equation has distinct solutions. By Lagrange's theorem, . On the other hand, Euler's theorem requires . Therefore, .
For with , start by proving that is an element of order . We have
Hence . Also, let a primitive root modulo , denoted by , be given. Since , Property 2 gives . By the definition of the Carmichael function and Euler's theorem,
Therefore, .
Summarizing the results of this section gives the recurrence formula for the Carmichael function:
Theorem
For every positive integer ,
Using this recurrence formula strengthens the preceding result:
Corollary
For positive integers , .
Comparing the definitions of a primitive root and the Carmichael function shows that a primitive root modulo exists if and only if . The recurrence formula for the Carmichael function readily yields the following result by induction:
Corollary
A primitive root modulo exists if and only if , where is an odd prime and .
Since the proof of the recurrence formula in this section did not use the primitive-root existence theorem, this gives another proof of that theorem.
Carmichael numbers
The Carmichael function can be used to study the properties and distribution of Carmichael numbers (OEIS:A002997). These are composite numbers that Fermat primality testing can never correctly reject.
Carmichael number
For a composite number , if for every integer the congruence holds, that number is called a Carmichael number.
The smallest Carmichael number is .
By the definition of the Carmichael function, a composite number is a Carmichael number if and only if , where is the Carmichael function. This gives the following test for whether a composite number is a Carmichael number:
Korselt's criterion11
A composite number is a Carmichael number if and only if is square-free and, for each prime factor of , denoted by , .
Proof
First prove necessity. Suppose . Examining the recurrence formula for the Carmichael function shows that if has a squared prime factor , then . But , a contradiction. Similarly, the recurrence formula shows that , and hence .
Now prove sufficiency. Since is composite, it has an odd prime factor , so is even and must be odd. For an odd square-free composite number , the recurrence formula for the Carmichael function gives . Therefore, if holds for every prime factor , then .
This criterion gives several simple properties of Carmichael numbers:
Corollary
Carmichael numbers are odd, square-free, and have at least distinct prime factors.
Proof
The first two properties follow directly from Korselt's criterion and its proof. For the third, it suffices to show that the product of two distinct primes , cannot be a Carmichael number. Suppose is a Carmichael number. By Korselt's criterion, . But
Therefore, . Similarly, . Hence , contradicting the assumption. Thus a Carmichael number has at least distinct prime factors.
Analytic number theory also gives properties of the distribution of Carmichael numbers. Let be the number of Carmichael numbers less than or equal to . Alford, Granville, and Pomerance12 proved that, for sufficiently large , . Thus there are infinitely many Carmichael numbers. Earlier, Erdős13 had proved that , where is a constant. Thus Carmichael numbers are quite sparse in distribution (relative to primes). In fact, 14 , .
References and notes
- Primitive root modulo n - Wikipedia
- The order of a unit - Course Notes
- The primitive root theorem - Amin Witno's notes
- Carmichael function - Wikipedia
- Carmichael's Lambda Function - Brilliant Math & Science Wiki
- Carmichael number - Wikipedia
- Carmichael Number - Wolfram MathWorld
Footnotes
-
Wang Y. "On the least primitive root of a prime." (in Chinese). Acta Math Sinica, 1959, 4: 432–441; English transl. inSci. Sinica, 1961, 10: 1–14. ↩
-
BURGESS, David A. "On character sums and primitive roots." Proceedings of the London Mathematical Society, 1962, 3.1: 179-192. ↩
-
Cohen, S. D., R. W. K. Odoni, and W. W. Stothers. "On the least primitive root modulo p 2." Bulletin of the London Mathematical Society 6, no. 1 (1974): 42-46. ↩
-
Elliott, P. D. T. A., and L. Murata. "The least primitive root mod 2p2." Mathematika 45, no. 2 (1998): 371-379. ↩ ↩2
-
FRIDLENDER, V. R. "On the least n-th power non-residue." Dokl. Akad. Nauk SSSR. 1949. p. 351-352. ↩
-
SALIÉ, Hans. "Über den kleinsten positiven quadratischen Nichtrest nach einer Primzahl." Mathematische Nachrichten, 1949, 3.1: 7-8. ↩
-
Burgess, D. A., and P. D. T. A. Elliott. "The average of the least primitive root." Mathematika 15, no. 1 (1968): 39-50. ↩
-
Elliott, Peter DTA, and Leo Murata. "On the average of the least primitive root modulo p." Journal of The london Mathematical Society 56, no. 3 (1997): 435-454. ↩
-
More results can be found in Least prime primitive root of prime numbers. ↩
-
If a primitive root modulo exists, then , with equality only when . Furthermore, when , the Euler totient function satisfies . Combining these two estimates gives the expression in the text. For this estimate of the Euler totient function, see Rosser, J. Barkley, and Lowell Schoenfeld. "Approximate formulas for some functions of prime numbers." Illinois Journal of Mathematics 6, no. 1 (1962): 64-94. ↩
-
Korselt, A. R. (1899). "Problème chinois." L'Intermédiaire des Mathématiciens. 6: 142–143. ↩
-
W. R. Alford; Andrew Granville; Carl Pomerance (1994). "There are Infinitely Many Carmichael Numbers." Annals of Mathematics. 140 (3): 703–722. ↩
-
Erdős, P. (1956). "On pseudoprimes and Carmichael numbers." Publ. Math. Debrecen. 4 (3–4): 201–206. ↩
-
PINCH, Richard GE. The Carmichael numbers up to . ↩