The Order of an Element and Primitive Roots

Fix a prime pp and consider the powers of a fixed nonzero residue modulo pp. How many distinct values can a,a2,a3,…a, a^2, a^3, \dots take? How many before the pattern repeats? This question of "multiplicative order" turns out to have a shockingly clean answer. It leads to one of the most elegant existence theorems in elementary number theory. Among the residues modulo a prime, some element's powers sweep out every nonzero residue. Such an element is called a primitive root. Its existence transforms the multiplicative structure of (Z/pZ)×(\mathbb{Z}/p\mathbb{Z})^\times from an abstract group into something concrete. It becomes like a clock face with p−1p-1 hours, generated by a single tick. This matters because it converts multiplicative problems into additive ones. Once a primitive root gg is fixed, every nonzero residue mod pp is gkg^k. This holds for a unique exponent kk modulo p−1p-1 — a discrete logarithm. Multiplication of residues becomes addition of exponents. This works exactly as ordinary logarithms convert multiplication into addition of real numbers. This single idea underlies the structure theorem for (Z/pZ)×(\mathbb{Z}/p\mathbb{Z})^\times. It also underlies the existence and counting of kk-th power residues, quadratic reciprocity's cousins, and modern discrete-logarithm-based cryptography. The big picture is this: (Z/pZ)×(\mathbb{Z}/p\mathbb{Z})^\times is a group of order p−1p-1. It is not just abstractly cyclic. We can point to explicit generators and understand exactly how many there are. The proof rests on two pillars. The first is Lagrange's Theorem on polynomial roots modulo a prime. It bounds how many solutions a polynomial congruence can have. The second is a careful counting argument using Euler's totient function. Nothing here requires machinery beyond what a first course in elementary number theory provides. Yet the conclusion is genuinely deep. This article builds the theory of multiplicative order from first principles. It proves that order always divides φ(n)\varphi(n), a strengthening of Euler's Theorem and Fermat's Little Theorem. It then proves the primitive root theorem for primes in full. This includes an exact count of how many primitive roots exist.

Key takeaways
  • The order of aa modulo nn (with gcd⁡(a,n)=1\gcd(a,n)=1) is the least positive integer dd with ad≡1(modn)a^d \equiv 1 \pmod n.
  • The order of aa always divides φ(n)\varphi(n); this refines Euler's theorem aφ(n)≡1(modn)a^{\varphi(n)} \equiv 1 \pmod n.
  • ak≡1(modn)a^k \equiv 1 \pmod n if and only if ord⁡n(a)∣k\operatorname{ord}_n(a) \mid k — order controls all powers that hit 1.
  • A primitive root mod pp is an element of order exactly p−1p-1; its powers list every nonzero residue.
  • Every prime pp has a primitive root, and exactly φ(p−1)\varphi(p-1) of the residues 1,…,p−11,\dots,p-1 are primitive roots.
  • Key idea: the multiplicative group mod a prime is cyclic, and this is proved by counting elements of each possible order using Lagrange's theorem on roots of polynomials.

Where this lives today

Primitive roots give an explicit isomorphism (Z/pZ)×≅Z/(p−1)Z(\mathbb{Z}/p\mathbb{Z})^\times \cong \mathbb{Z}/(p-1)\mathbb{Z}, turning multiplicative questions into additive ones via discrete logarithms — this is the working engine behind Diffie–Hellman key exchange, the ElGamal cryptosystem, and digital signature algorithms (DSA), all of which rely on the presumed computational difficulty of inverting gk↦kg^k \mapsto k even though the forward direction is easy. Primitive roots are also essential in constructing Paley graphs and quadratic residue codes in combinatorics, in the classical theory of Gauss sums and cyclotomy, in fast algorithms for the discrete Fourier transform over finite fields (number-theoretic transforms, used in fast polynomial multiplication), and in generating pseudo-random sequences for linear congruential generators, where the multiplier's order controls the period of the generator. The order-divides-φ(n)\varphi(n) principle is also the elementary engine behind primality tests such as Lucas' primality test and the Pocklington/Proth tests, which certify primality by exhibiting an element of large order.

Ask the tutor: How do you use a primitive root modulo pp to count and construct all quadratic (and higher-power) residues?

DefinitionMultiplicative order and primitive root

Let n≥1n \geq 1 be an integer and let aa be an integer with gcd⁡(a,n)=1\gcd(a,n) = 1. Since aφ(n)≡1(modn)a^{\varphi(n)} \equiv 1 \pmod n by Euler's theorem, the set

S={k∈Z>0:ak≡1(modn)}S = \{k \in \mathbb{Z}_{>0} : a^k \equiv 1 \pmod n\}

is nonempty. The order of aa modulo nn, written ord⁡n(a)\operatorname{ord}_n(a), is min⁡S\min S, the least positive integer dd such that

ad≡1(modn).a^d \equiv 1 \pmod n.

If n=pn = p is prime and ord⁡p(a)=p−1=φ(p)\operatorname{ord}_p(a) = p - 1 = \varphi(p), then aa is called a primitive root modulo pp (equivalently, a primitive root of unity mod pp, or a generator of (Z/pZ)×(\mathbb{Z}/p\mathbb{Z})^\times).

Intuition

Think of the nonzero residues mod pp arranged on a circle of p−1p-1 points, and think of multiplying by a fixed aa as a rotation-like permutation of that circle. Repeatedly applying "multiply by aa" to the residue 11 traces out a cycle: 1,a,a2,a3,…1, a, a^2, a^3, \dots, and because there are only finitely many residues, this sequence must eventually return to 11. The order of aa is exactly the length of that cycle — the smallest number of steps to get back home. The subtle and beautiful fact is that this cycle length is not arbitrary: it must divide φ(n)\varphi(n), the size of the whole group of units. This is a special case of Lagrange's theorem from group theory (the order of an element divides the order of the group), but we will prove it directly using only division-with-remainder, without invoking group theory as a black box. The primitive root phenomenon is the extreme case: for n=pn = p prime, there is always some aa whose cycle has the maximum possible length p−1p-1, meaning its powers visit every single nonzero residue before returning to 1. The picture below shows this for p=7p = 7 with a=3a = 3: the powers of 3 cycle through all six nonzero residues mod 7, while the powers of 2 only visit three of them (order 3), a proper subgroup.

Figure
Powers of 3 (order 6, primitive root) vs. powers of 2 (order 3) modulo 7
Orbit of 3 mod 7 (full cycle) 1 3 2 6 4 5 3^0..3^5 = 1,3,2,6,4,5 (all 6 residues) Orbit of 2 mod 7 (subgroup, order 3) 1 3 2 6 4 5 2^0..2^2 = 1,2,4 then repeats

Order divides φ(n)\varphi(n)

TheoremDivision property of order

Let n≥1n \geq 1 and let aa be an integer with gcd⁡(a,n)=1\gcd(a,n) = 1. Let d=ord⁡n(a)d = \operatorname{ord}_n(a). Then for any positive integer kk,

ak≡1(modn)  ⟺  d∣k.a^k \equiv 1 \pmod n \iff d \mid k.

In particular, taking k=φ(n)k = \varphi(n) and using Euler's theorem, d∣φ(n)d \mid \varphi(n).

Proof

We use the division algorithm, the technique of writing k=qd+rk = qd + r with 0≤r<d0 \le r < d. (⇐\Leftarrow) Suppose d∣kd \mid k, say k=mdk = md for some positive integer mm. Since ad≡1(modn)a^d \equiv 1 \pmod n by definition of order, raising both sides to the mm-th power gives

ak=(ad)m≡1m=1(modn).a^k = (a^d)^m \equiv 1^m = 1 \pmod n.

(⇒\Rightarrow) Suppose ak≡1(modn)a^k \equiv 1 \pmod n. By the division algorithm applied to kk and dd, write

k=qd+r,0≤r<d,k = qd + r, \qquad 0 \le r < d,

for unique integers q,rq, r. Then

ar=ak−qd=ak⋅(ad)−q.a^r = a^{k - qd} = a^k \cdot (a^d)^{-q}.

More carefully (to avoid negative exponents before establishing invertibility, though aa is already a unit mod nn since gcd⁡(a,n)=1\gcd(a,n)=1): from ak=aqd⋅ara^k = a^{qd} \cdot a^r we get

ar≡ak⋅(ad)−q≡1⋅(1)−q≡1(modn),a^r \equiv a^k \cdot (a^d)^{-q} \equiv 1 \cdot (1)^{-q} \equiv 1 \pmod n,

using ak≡1a^k \equiv 1 and ad≡1a^d \equiv 1, and the fact that aa (hence ada^d) is invertible mod nn because gcd⁡(a,n)=1\gcd(a,n) = 1 (this is the standard fact that invertibility mod nn is equivalent to being coprime to nn, established via Modular Inverses and Bézout's identity). So ar≡1(modn)a^r \equiv 1 \pmod n with 0≤r<d0 \le r < d. But dd is by definition the least positive integer with ad≡1(modn)a^d \equiv 1 \pmod n. If rr were a positive integer less than dd with ar≡1a^r \equiv 1, this would contradict minimality of dd. Hence we must have r=0r = 0 (the only non-positive option in range, since r≥0r \geq 0). Therefore k=qdk = qd, i.e. d∣kd \mid k. Finally, by Euler's Theorem, aφ(n)≡1(modn)a^{\varphi(n)} \equiv 1 \pmod n (valid since gcd⁡(a,n)=1\gcd(a,n)=1). Applying the equivalence just proved with k=φ(n)k = \varphi(n) gives d∣φ(n)d \mid \varphi(n), i.e. ord⁡n(a)∣φ(n)\operatorname{ord}_n(a) \mid \varphi(n). ■\blacksquare

∎
CorollaryFermat's Little Theorem as a special case

If pp is prime and p∤ap \nmid a, then ord⁡p(a)∣(p−1)\operatorname{ord}_p(a) \mid (p-1), and consequently ap−1≡1(modp)a^{p-1} \equiv 1 \pmod p. This recovers Fermat's Little Theorem and shows that the order of any nonzero residue mod pp is a divisor of p−1p - 1 — a strong constraint we exploit below.

Lagrange's theorem on roots mod pp

The primitive root theorem needs one more tool: a bound on how many solutions a polynomial congruence can have modulo a prime.

LemmaLagrange's theorem on polynomial congruences

Let pp be prime and let

f(x)=cmxm+cm−1xm−1+⋯+c1x+c0f(x) = c_m x^m + c_{m-1}x^{m-1} + \cdots + c_1 x + c_0

be a polynomial with integer coefficients, degree m≥1m \ge 1 (i.e. cm≢0(modp)c_m \not\equiv 0 \pmod p). Then the congruence

f(x)≡0(modp)f(x) \equiv 0 \pmod p

has at most mm solutions modulo pp (i.e. at most mm pairwise incongruent residues xx satisfy it).

Proof

We induct on mm, using the factor theorem mod pp together with the fact that Z/pZ\mathbb{Z}/p\mathbb{Z} has no zero divisors (a direct consequence of pp being prime: if p∣uvp \mid uv then p∣up \mid u or p∣vp \mid v, Euclid's lemma). Base case m=1m = 1: f(x)=c1x+c0f(x) = c_1 x + c_0 with c1≢0c_1 \not\equiv 0. The congruence c1x≡−c0(modp)c_1 x \equiv -c_0 \pmod p has a unique solution mod pp since c1c_1 is invertible mod pp (as p∤c1p \nmid c_1, via Bézout). So there is exactly 1≤11 \le 1 solution. Inductive step: Suppose the claim holds for all degrees less than mm. If f(x)≡0(modp)f(x) \equiv 0 \pmod p has no solutions, the bound 0≤m0 \le m holds trivially. Otherwise let aa be one solution: f(a)≡0(modp)f(a) \equiv 0 \pmod p. Perform polynomial division with remainder over Z\mathbb{Z}: since the leading coefficient of (x−a)(x - a) is 11 (a unit), we can write

f(x)=(x−a)g(x)+rf(x) = (x - a) g(x) + r

for a polynomial gg of degree m−1m - 1 with integer coefficients and a constant r∈Zr \in \mathbb{Z} (ordinary polynomial division, valid over any commutative ring when dividing by a monic polynomial). Substituting x=ax = a: f(a)=rf(a) = r, so r≡0(modp)r \equiv 0 \pmod p since f(a)≡0f(a) \equiv 0. Hence

f(x)≡(x−a)g(x)(modp)f(x) \equiv (x-a) g(x) \pmod p

as polynomials, i.e. coefficientwise mod pp (subtracting the two sides gives the zero polynomial mod pp, since r≡0r \equiv 0). The leading coefficient of gg equals the leading coefficient of ff, namely cm≢0(modp)c_m \not\equiv 0 \pmod p, so gg has degree exactly m−1m - 1 as a polynomial mod pp. By the inductive hypothesis, g(x)≡0(modp)g(x) \equiv 0 \pmod p has at most m−1m - 1 solutions mod pp. Now suppose bb is any solution of f(x)≡0(modp)f(x) \equiv 0 \pmod p. Then (b−a)g(b)≡0(modp)(b - a) g(b) \equiv 0 \pmod p. Since Z/pZ\mathbb{Z}/p\mathbb{Z} has no zero divisors, either b≡a(modp)b \equiv a \pmod p, or g(b)≡0(modp)g(b) \equiv 0 \pmod p. The first case gives exactly one residue (aa itself); the second case gives at most m−1m-1 residues by the inductive hypothesis. So the total number of solutions is at most 1+(m−1)=m1 + (m-1) = m. This completes the induction. ■\blacksquare

∎

The primitive root theorem

TheoremExistence and count of primitive roots mod a prime

Let pp be a prime. Then: 1. For every divisor dd of p−1p - 1, the number of residues a∈{1,2,…,p−1}a \in \{1, 2, \dots, p-1\} with ord⁡p(a)=d\operatorname{ord}_p(a) = d is either 00 or exactly φ(d)\varphi(d). 2. In fact this count is always exactly φ(d)\varphi(d), for every divisor dd of p−1p-1. 3. In particular (taking d=p−1d = p - 1), there are exactly φ(p−1)\varphi(p-1) primitive roots modulo pp among 1,…,p−11, \dots, p-1. Since φ(p−1)≥1\varphi(p-1) \geq 1 for every p−1≥1p - 1 \ge 1, a primitive root modulo pp always exists.

Proof

We use three ingredients already established: the division property of order, Lagrange's Theorem on polynomial roots mod pp, and basic properties of Euler's totient (specifically ∑d∣mφ(d)=m\sum_{d \mid m} \varphi(d) = m).

Setup. For each divisor dd of p−1p-1, let ψ(d)\psi(d) denote the number of a∈{1,…,p−1}a \in \{1, \dots, p-1\} with ord⁡p(a)=d\operatorname{ord}_p(a) = d. Every residue a∈{1,…,p−1}a \in \{1,\dots,p-1\} has some order dividing p−1p-1 (Corollary above), so

∑d∣p−1ψ(d)=p−1.(∗)\sum_{d \mid p-1} \psi(d) = p - 1. \tag{$\ast$}

Step 1: bounding ψ(d)\psi(d) via Lagrange. Fix a divisor d∣(p−1)d \mid (p-1). Consider the polynomial congruence

xd−1≡0(modp).x^d - 1 \equiv 0 \pmod p.

By the Lemma (Lagrange's theorem), this has at most dd solutions mod pp. Now if ord⁡p(a)=d\operatorname{ord}_p(a) = d, then ad≡1(modp)a^d \equiv 1 \pmod p, so aa is one of these at-most-dd solutions. Hence the elements of order exactly dd form a subset of the (at most dd) roots of xd−1≡0x^d - 1 \equiv 0.

Step 2: if there is one element of order dd, there are exactly φ(d)\varphi(d). Suppose ψ(d)>0\psi(d) > 0, and fix some a0a_0 with ord⁡p(a0)=d\operatorname{ord}_p(a_0) = d. Consider the dd powers

a00,a01,a02,…,a0d−1(modp).a_0^0, a_0^1, a_0^2, \dots, a_0^{d-1} \pmod p.

These are pairwise incongruent mod pp: if a0i≡a0j(modp)a_0^i \equiv a_0^j \pmod p with 0≤i<j≤d−10 \le i < j \le d-1, then a0j−i≡1(modp)a_0^{j-i} \equiv 1 \pmod p (using invertibility of a0a_0 mod pp) with 0<j−i<d0 < j - i < d, contradicting that dd is the least positive exponent giving 11. So these dd powers are dd distinct residues mod pp. Each of them satisfies (a0i)d=(a0d)i≡1i≡1(modp)(a_0^i)^d = (a_0^d)^i \equiv 1^i \equiv 1 \pmod p, so each is a root of xd−1≡0(modp)x^d - 1 \equiv 0 \pmod p. Since that congruence has at most dd roots (Step 1) and we have exhibited dd distinct roots, these powers a00,…,a0d−1a_0^0, \dots, a_0^{d-1} constitute all the roots of xd≡1(modp)x^d \equiv 1 \pmod p. In particular, every element of order exactly dd must be among {a00,…,a0d−1}\{a_0^0, \dots, a_0^{d-1}\}, since such elements satisfy xd≡1x^d \equiv 1. So it remains to count, among these dd powers, how many have order exactly dd (as opposed to a proper divisor of dd).

Claim: ord⁡p(a0i)=dgcd⁡(i,d)\operatorname{ord}_p(a_0^i) = \dfrac{d}{\gcd(i,d)} for 0≤i≤d−10 \le i \le d - 1. Proof of claim. Let g=gcd⁡(i,d)g = \gcd(i, d), and let e=ord⁡p(a0i)e = \operatorname{ord}_p(a_0^i). We show e=d/ge = d/g. First, (a0i)d/g=a0id/g=(a0d)i/g≡1(modp)(a_0^i)^{d/g} = a_0^{i d / g} = (a_0^d)^{i/g} \equiv 1 \pmod p — here i/gi/g is an integer since g∣ig \mid i. So e∣(d/g)e \mid (d/g) by the division property of order (applied to the element a0ia_0^i, whose order is ee, with k=d/gk = d/g). Conversely, (a0i)e≡1(modp)(a_0^i)^e \equiv 1 \pmod p means a0ie≡1(modp)a_0^{ie} \equiv 1 \pmod p, so by the division property applied to a0a_0 (order dd), we get d∣ied \mid ie. Write i=gi′i = g i', d=gd′d = g d' with gcd⁡(i′,d′)=1\gcd(i', d') = 1 (dividing by the gcd). Then d∣ie  ⟺  gd′∣gi′e  ⟺  d′∣i′ed \mid ie \iff g d' \mid g i' e \iff d' \mid i' e. Since gcd⁡(d′,i′)=1\gcd(d', i') = 1, Euclid's lemma / Bézout gives d′∣ed' \mid e, i.e. (d/g)∣e(d/g) \mid e. Combining e∣(d/g)e \mid (d/g) and (d/g)∣e(d/g) \mid e with both positive gives e=d/ge = d/g, proving the claim. □\square

Step 3: finishing the count. By the claim, a0ia_0^i has order exactly dd if and only if gcd⁡(i,d)=1\gcd(i, d) = 1. The number of i∈{0,1,…,d−1}i \in \{0, 1, \dots, d-1\} with gcd⁡(i,d)=1\gcd(i,d) = 1 is, by definition, φ(d)\varphi(d) (note gcd⁡(0,d)=d≠1\gcd(0,d) = d \ne 1 unless d=1d=1, consistent with the definition). Since we showed the elements of order dd among 1,…,p−11,\dots,p-1 are exactly {a0i:gcd⁡(i,d)=1}\{a_0^i : \gcd(i,d)=1\}, we conclude

ψ(d)=φ(d)whenever ψ(d)>0.\psi(d) = \varphi(d) \quad \text{whenever } \psi(d) > 0.

Step 4: ψ(d)>0\psi(d) > 0 for every d∣(p−1)d \mid (p-1). We now know each ψ(d)\psi(d) is either 00 or φ(d)\varphi(d), so

ψ(d)≤φ(d)for every d∣p−1.\psi(d) \le \varphi(d) \quad \text{for every } d \mid p - 1.

Summing over all d∣p−1d \mid p-1 and using (∗)(\ast):

p−1=∑d∣p−1ψ(d)≤∑d∣p−1φ(d)=p−1,p - 1 = \sum_{d \mid p-1} \psi(d) \le \sum_{d \mid p - 1} \varphi(d) = p - 1,

where the last equality is the standard totient identity ∑d∣mφ(d)=m\sum_{d\mid m}\varphi(d) = m applied to m=p−1m = p-1 (proved by partitioning {1,…,m}\{1,\dots,m\} according to gcd⁡(k,m)\gcd(k,m)). Since the sum of the ψ(d)\psi(d) equals the sum of the (larger-or-equal) φ(d)\varphi(d), and each term satisfies ψ(d)≤φ(d)\psi(d) \le \varphi(d), every single inequality must be an equality: if some ψ(d0)<φ(d0)\psi(d_0) < \varphi(d_0) strictly, the total sum ∑ψ(d)\sum \psi(d) would be strictly less than ∑φ(d)=p−1\sum \varphi(d) = p-1, contradicting (∗)(\ast). Hence

ψ(d)=φ(d)for every d∣p−1.\psi(d) = \varphi(d) \quad \text{for every } d \mid p - 1.

This proves parts (1) and (2). For part (3), set d=p−1d = p - 1: the number of primitive roots is ψ(p−1)=φ(p−1)\psi(p-1) = \varphi(p-1). Since φ(m)≥1\varphi(m) \ge 1 for every positive integer mm (as gcd⁡(m,m)=m\gcd(m,m)=m, but more simply φ(1)=1\varphi(1)=1 and generally φ(m)≥1\varphi(m)\ge 1 because 11 is always coprime to mm), we get φ(p−1)≥1\varphi(p-1) \ge 1, so at least one primitive root exists. ■\blacksquare

∎

Worked examples

Example 1: orders modulo p=13p = 13 (so p−1=12p - 1 = 12), a non-symmetric case. We compute the order of a=7a = 7 modulo 1313. The divisors of 1212 are 1,2,3,4,6,121,2,3,4,6,12, and by the division property, ord⁡13(7)\operatorname{ord}_{13}(7) must be one of these. Compute successive powers of 77 mod 1313:

71=7,72=49≡10,73≡7⋅10=70≡5,74≡7⋅5=35≡9,7^1 = 7,\quad 7^2 = 49 \equiv 10,\quad 7^3 \equiv 7\cdot 10 = 70 \equiv 5,\quad 7^4 \equiv 7 \cdot 5 = 35 \equiv 9,
76≡74⋅72≡9⋅10=90≡12≡−1,712≡(76)2≡(−1)2=1.7^6 \equiv 7^4 \cdot 7^2 \equiv 9 \cdot 10 = 90 \equiv 12 \equiv -1, \qquad 7^{12} \equiv (7^6)^2 \equiv (-1)^2 = 1.

Since 76≡−1≢17^6 \equiv -1 \not\equiv 1, the order does not divide 66; since 74≡9≠17^4 \equiv 9 \ne 1, order doesn't divide 44; since 73≡5≠17^3 \equiv 5 \ne 1, order doesn't divide 33. The only divisor of 1212 not dividing 66, 44, or 33 (other than through the chain) that remains consistent is 1212 itself — let's confirm directly: the divisors of 1212 are {1,2,3,4,6,12}\{1,2,3,4,6,12\}. We've ruled out 11 (since 7≠17\ne1), 22 (since 72=10≠17^2 = 10 \ne 1), 3,4,63,4,6 as shown. So ord⁡13(7)=12\operatorname{ord}_{13}(7) = 12, meaning 77 is a primitive root mod 1313. Cross-check via the theorem: φ(12)=φ(4)φ(3)=2⋅2=4\varphi(12) = \varphi(4)\varphi(3) = 2 \cdot 2 = 4, so there should be exactly 44 primitive roots mod 1313 among {1,…,12}\{1,\dots,12\}. Using the claim from the proof, if 77 is a primitive root, the full list of primitive roots is {7i  13:gcd⁡(i,12)=1, 0≤i<12}\{7^i \bmod 13 : \gcd(i,12) = 1,\ 0 \le i < 12\}, i.e. i∈{1,5,7,11}i \in \{1,5,7,11\}:

71≡7,75≡74⋅7≡9⋅7=63≡11,77≡76⋅7≡(−1)(7)≡6,711≡712⋅7−1≡7−1.7^1 \equiv 7,\quad 7^5 \equiv 7^4 \cdot 7 \equiv 9\cdot 7 = 63 \equiv 11,\quad 7^7 \equiv 7^6\cdot 7 \equiv (-1)(7) \equiv 6,\quad 7^{11}\equiv 7^{12}\cdot 7^{-1}\equiv 7^{-1}.

Since 7⋅2=14≡17 \cdot 2 = 14 \equiv 1, we get 7−1≡27^{-1} \equiv 2. So the primitive roots mod 1313 are {7,11,6,2}\{7, 11, 6, 2\} — four values, matching φ(12)=4\varphi(12) = 4 exactly.

Example 2: counting elements of each order mod p=11p = 11 (p−1=10p - 1 = 10), verifying the full divisor structure. Divisors of 1010: 1,2,5,101, 2, 5, 10, with φ(1)=1, φ(2)=1, φ(5)=4, φ(10)=4\varphi(1)=1,\ \varphi(2)=1,\ \varphi(5)=4,\ \varphi(10)=4, summing to 1+1+4+4=101+1+4+4=10, consistent with ∑d∣10φ(d)=10\sum_{d\mid 10}\varphi(d) = 10. We claim 22 is a primitive root mod 1111. Compute powers of 22 mod 1111:

21=2, 22=4, 23=8, 24=16≡5, 25≡10, 26≡20≡9,2^1=2,\ 2^2=4,\ 2^3=8,\ 2^4=16\equiv5,\ 2^5\equiv10,\ 2^6\equiv20\equiv9,
27≡18≡7, 28≡14≡3, 29≡6, 210≡12≡1.2^7\equiv18\equiv7,\ 2^8\equiv14\equiv3,\ 2^9\equiv6,\ 2^{10}\equiv12\equiv1.

Indeed 210≡12^{10}\equiv1 and no smaller positive power (checking 21,…,292^1,\dots,2^9 above, none equal 11) equals 11, and since order must divide 1010 (divisors 1,2,51,2,5 all checked as giving 2,4,10≠12,4,10\ne1), the order is exactly 1010. So 22 generates all of {1,…,10}\{1,\dots,10\} as its powers — confirmed by the list {2,4,8,5,10,9,7,3,6,1}\{2,4,8,5,10,9,7,3,6,1\}, which is a permutation of {1,…,10}\{1,\dots,10\}. Now classify every element's order using ord⁡11(2i)=10/gcd⁡(i,10)\operatorname{ord}_{11}(2^i) = 10/\gcd(i,10):

ii2i  112^i \bmod 11gcd⁡(i,10)\gcd(i,10)order =10/gcd⁡=10/\gcd
01101
12110
2425
38110
4525
51052
6925
77110
8325
96110

Tally: order 11: just {1}\{1\} — count 1=φ(1)1 = \varphi(1). Order 22: just {10}\{10\} — count 1=φ(2)1=\varphi(2). Order 55: {4,5,9,3}\{4,5,9,3\} — count 4=φ(5)4 = \varphi(5). Order 1010 (primitive roots): {2,8,7,6}\{2,8,7,6\} — count 4=φ(10)4=\varphi(10). Totals: 1+1+4+4=101+1+4+4=10, matching p−1=11−1=10p-1=11-1=10 exactly, and every count matches φ(d)\varphi(d) precisely as the theorem predicts.

CounterexampleWhy primality of the modulus is needed

The primitive root theorem is stated for prime pp. If we drop primality and allow composite nn, the conclusion — existence of an element whose powers hit every unit mod nn — can fail entirely. Take n=8n = 8. The units mod 88 are {1,3,5,7}\{1,3,5,7\}, so φ(8)=4\varphi(8) = 4. Compute orders:

32=9≡1(mod8),52=25≡1(mod8),72=49≡1(mod8).3^2 = 9 \equiv 1 \pmod 8,\qquad 5^2 = 25 \equiv 1 \pmod 8, \qquad 7^2 = 49 \equiv 1 \pmod 8.

So ord⁡8(3)=ord⁡8(5)=ord⁡8(7)=2\operatorname{ord}_8(3) = \operatorname{ord}_8(5) = \operatorname{ord}_8(7) = 2, and trivially ord⁡8(1)=1\operatorname{ord}_8(1) = 1. Every unit mod 88 has order at most 22, while φ(8)=4\varphi(8) = 4. No element has order 44, so there is no primitive root modulo 88 — the group (Z/8Z)×(\mathbb{Z}/8\mathbb{Z})^\times is not cyclic (it is isomorphic to the Klein four-group Z/2×Z/2\mathbb{Z}/2 \times \mathbb{Z}/2). The step of the proof that breaks is Lagrange's theorem on polynomial roots: that lemma crucially used that Z/pZ\mathbb{Z}/p\mathbb{Z} has no zero divisors, which fails for composite moduli. Modulo 88, the congruence x2≡1(mod8)x^2 \equiv 1 \pmod 8 has four solutions (1,3,5,71,3,5,7), not at most 22 as Lagrange's bound would give for a prime modulus — because 88 is not prime, the "at most deg⁡f\deg f roots" bound simply does not apply. This is exactly why the primitive root theorem, as proved above, is restricted to prime moduli; extending it to composite nn requires separate, more delicate analysis (it turns out primitive roots mod nn exist exactly when n∈{1,2,4,pk,2pk}n \in \{1,2,4,p^k,2p^k\} for odd prime pp, a genuinely different and harder theorem).

Scope, edge cases & common traps

SituationWhat holdsWhat can fail
nn primePrimitive root always exists; count is φ(p−1)\varphi(p-1)—
n=1n = 1Every integer is ≡0\equiv 0; convention: φ(1)=1\varphi(1)=1, trivial groupOrder concept degenerate
nn composite, e.g. 8,12,158, 12, 15Order still divides φ(n)\varphi(n)Primitive root may not exist (group not cyclic)
gcd⁡(a,n)>1\gcd(a,n) > 1Order is undefinedak≡1(modn)a^k \equiv 1 \pmod n is impossible if gcd⁡(a,n)>1\gcd(a,n)>1, n>1n>1
Computing orderMust check all divisors of φ(n)\varphi(n), not just test aφ(n)/qa^{\varphi(n)/q} for one prime qqSkipping divisors gives wrong (too-small or too-large) order

The mathematician behind it

Origins · 1 minCarl Friedrich Gauss and how this was discovered
CF
Carl Friedrich Gauss
1777–1855 · Göttingen, foundational work in number theory

Gauss developed the systematic theory of congruences, multiplicative order, and primitive roots in his 1801 treatise Disquisitiones Arithmeticae, written when he was still in his early twenties. He proved the existence of primitive roots modulo any prime (and characterized exactly which moduli admit them at all), introduced the modern notation for congruence (≡\equiv), and used primitive roots as the key tool to build "indices" — discrete logarithms — that reduced multiplicative congruence problems to additive ones, directly foreshadowing quadratic reciprocity and the theory of binary quadratic forms.

History
- 1750s–1760s: Euler studies powers of residues and proves special cases of Fermat's little theorem and totient properties.
- 1801: Gauss publishes Disquisitiones Arithmeticae, giving the first complete, rigorous treatment of order, primitive roots, and their count φ(p−1)\varphi(p-1).
- 1801: Gauss determines exactly which moduli nn possess primitive roots (1,2,4,pk,2pk1,2,4,p^k,2p^k).
- 1830s–1840s: Jacobi builds tables of indices (discrete logarithms) with respect to primitive roots for computational number theory.
- 20th century: discrete logarithm problem modulo primes becomes a cornerstone of public-key cryptography.
Does every integer have a well-defined multiplicative order modulo nn?

No — order is only defined for aa with gcd⁡(a,n)=1\gcd(a,n) = 1. If gcd⁡(a,n)=g>1\gcd(a,n) = g > 1, then for every positive kk, gcd⁡(ak,n)\gcd(a^k, n) is also divisible by any prime factor shared by aa and nn, so ak≡1(modn)a^k \equiv 1 \pmod n is impossible (since 11 is coprime to nn whenever n>1n > 1). The set defining order would be empty, so no minimum exists. This is why every theorem about order explicitly assumes gcd⁡(a,n)=1\gcd(a,n)=1; it is not a minor technicality but a precondition for the definition to make sense at all.

Why does order divide φ(n)\varphi(n) rather than merely satisfy aφ(n)≡1a^{\varphi(n)}\equiv 1?

Euler's theorem only tells us φ(n)\varphi(n) is one exponent that works. The order is defined as the smallest positive exponent that works, and the division-algorithm argument shows that the set of all working exponents is precisely the multiples of the order. Since φ(n)\varphi(n) is a working exponent, it must be a multiple of the order — i.e., the order divides φ(n)\varphi(n). This is strictly stronger information: it restricts the order to one of the (often few) divisors of φ(n)\varphi(n), rather than leaving it anywhere in {1,…,φ(n)}\{1,\dots,\varphi(n)\}.

Is the primitive root of a prime unique?

No, generally not, except in tiny cases. There are exactly φ(p−1)\varphi(p-1) primitive roots modulo pp. For p=13p=13, φ(12)=4\varphi(12)=4, and we found all four explicitly: 2,6,7,112, 6, 7, 11. Uniqueness would only occur when φ(p−1)=1\varphi(p-1)=1, which happens only for p−1∈{1,2}p-1 \in \{1,2\}, i.e. p∈{2,3}p \in \{2,3\}. For every larger prime there are multiple primitive roots, related to each other as gig^i for ii coprime to p−1p-1.

How do you actually compute a primitive root in practice, rather than by exhaustive search?

Factor p−1p - 1 into its distinct prime factors q1,…,qrq_1, \dots, q_r. For a candidate aa, aa is a primitive root if and only if a(p−1)/qi≢1(modp)a^{(p-1)/q_i} \not\equiv 1 \pmod p for every ii — this is a direct consequence of the division property of order (if the order were a proper divisor of p−1p-1, it would divide (p−1)/qi(p-1)/q_i for some prime factor qiq_i). This reduces primitive-root testing from checking all divisors of p−1p-1 to checking only rr specific exponents, one per distinct prime factor of p−1p-1, making it efficient even for large primes.

Does the theorem say anything about how to find the smallest primitive root?

The theorem proved here guarantees existence and gives the exact count φ(p−1)\varphi(p-1), but it is purely existential — it does not construct a primitive root explicitly or bound the smallest one by an elementary formula. In practice the least primitive root is usually small (heuristically O((log⁡p)6)O((\log p)^6) under GRH, and empirically almost always under 100100), but proving good unconditional bounds on the least primitive root is a genuinely hard open problem in analytic number theory, well beyond the elementary methods used here.

What is the connection between primitive roots and discrete logarithms?

Once a primitive root gg mod pp is fixed, every unit a∈{1,…,p−1}a \in \{1,\dots,p-1\} can be written uniquely as a≡gk(modp)a \equiv g^k \pmod p for some k∈{0,1,…,p−2}k \in \{0,1,\dots,p-2\}; this kk is called the index or discrete logarithm of aa base gg. Because gi⋅gj=gi+jg^i \cdot g^j = g^{i+j}, multiplication of residues corresponds exactly to addition of their discrete logs modulo p−1p-1, exactly mirroring how ordinary logarithms convert multiplication to addition of real numbers. This dictionary is what makes primitive roots so powerful for both theoretical arguments (like counting power residues) and cryptographic constructions.

Why must ψ(d)≤φ(d)\psi(d) \le \varphi(d) before we can conclude equality by the summation trick?

The summation argument (comparing ∑ψ(d)\sum \psi(d) and ∑φ(d)\sum \varphi(d), both equal to p−1p-1) only forces every term to match if we already know term-by-term that ψ(d)≤φ(d)\psi(d) \le \varphi(d). Without that pointwise inequality, two sums being equal would say nothing about individual terms — some ψ(d)\psi(d) could exceed φ(d)\varphi(d) while another falls short, and the totals could still coincide. That is exactly why Steps 1–3 (proving ψ(d)∈{0,φ(d)}\psi(d) \in \{0, \varphi(d)\} using Lagrange's theorem) must come before the global summation comparison in Step 4; the logical order is essential, not merely stylistic.

Before this