Cyclicity of (Z/(p))× in Number Theory
Cyclicity of (Z/(p))× in Number Theory
KEITH CONRAD
1. Introduction
For a prime p, the group (Z/(p))× is cyclic. This is very important in number theory and
has had practical significance since a choice of generator of (Z/(p))× was used in early work
on public-key cryptography: the Diffie-Hellman key exchange from 1976 (found earlier in
classified work by British intelligence) and the ElGamal cryptosystem from 1985.1
We will give ten proofs that (Z/(p))× is cyclic. A feature of all known proofs is that
they do not lead to concrete formula for a generator in terms of p. The proof in Section
7 is an algorithm leading to a generator, but not efficiently since it depends on the prime
factorization of p − 1.
The cyclicity of (Z/(p))× was first conjectured by Lambert [4, Footnote 13], [7, pp. 127–
128] in 1769. Euler [5, §38] gave a proof like that in Section 9 in 1773, with some gaps.
Gauss [6, Art. 52–55] gave the proofs in Sections 2 and 7 in 1801, and cyclicity of (Z/(p))×
is often attributed to him.
Unlike prime moduli, for most (but not all) composite m the group (Z/(m))× is not
cyclic. For example, (Z/(12))× has size 4 but its elements have order 1 or 2.
The following result is used in all but the last three proofs that (Z/(p))× is cyclic, so we
state it now.
Theorem 1.1. Let f (T ) be a non-constant polynomial with coefficients in Z/(p), of degree
d. Then f (T ) has at most d roots in Z/(p).
Theorem 1.1 is proved in Appendix A. What we need from Theorem 1.1 is the special
case f (T ) = T d − 1: the congruence td − 1 ≡ 0 mod p has at most d solutions in Z/(p), or
equivalently, there are at most d solutions to the equation td − 1 = 0 in Z/(p). The upper
bound d can break down in Z/(m) for non-prime m, e.g., the polynomial T 2 − 1 has four
solutions in Z/(8).
If there is some d dividing p − 1 for which the inequality in (2.2) is strict (that is, Np (d) <
ϕ(d)), then the inequality in (2.3) would be strict, and thus the inequality in (2.4) would
be strict. How sharp is (2.4)? Let’s look at some examples.
P
Example 2.2. If p = 5, then d|4 ϕ(d) = ϕ(1) + ϕ(2) + ϕ(4) = 1 + 1 + 2 = 4.
P
Example 2.3. If p = 11, then d|10 ϕ(d) = ϕ(1) + ϕ(2) + ϕ(5) + ϕ(10) = 1 + 1 + 4 + 4 = 10.
P
Example 2.4. If p = 29, then d|28 ϕ(d) = ϕ(1) + ϕ(2) + ϕ(4) + ϕ(7) + ϕ(14) + ϕ(28) =
1 + 1 + 2 + 6 + 6 + 12 = 28.
It appears that (2.4) might be an equality! This inspires us to prove it, and the appearance
of p − 1 in (2.4) is not essential.
P
Theorem 2.5. For every positive integer n, d|n ϕ(d) = n. In particular, for each prime
P
number p we have d|(p−1) ϕ(d) = p − 1.
Proof. We will count the n fractions
1 2 n−1 n
(2.5) , , ..., ,
n n n n
according to their denominators when the fractions are put in reduced form.
For such a fraction m/n with denominator n, its reduced form denominator is a divisor
of n. How many of these reduced form fractions have a given denominator? Writing
m/n = a/d, where (a, d) = 1, the condition 1 ≤ m ≤ n is equivalent to 1 ≤ a ≤ d.
Therefore the number of fractions in (2.5) with reduced form denominator d is the number
of a from 1 to d with (a, d) = 1. There are ϕ(d) such numbers. Thus, counting the fractions
in (2.5) according to their reduced form denominators, we get
X
n= ϕ(d).
d|n
CYCLICITY OF (Z/(p))× 3
Theorem 2.5 tells us (2.4) is an equality, so the inequalities in (2.2) must all be equalities.
(Reread the discussion right after (2.4) if you don’t see this.) Therefore Np (d) = ϕ(d) for
each d dividing p − 1. In particular, Np (p − 1) > 0, so there is an element of (Z/(p))× with
order p − 1. We’ve (non-constructively) proved the existence of a generator of (Z/(p))× .
Let’s summarize the argument again.
Theorem 2.6. For each prime p, the group (Z/(p))× is cyclic.
Proof. For d ∈ Z+ , let Np (d) be the number of elements of order d in (Z/(p))× . By Theorem
2.1, Np (d) ≤ ϕ(d). Therefore
X X
p−1= Np (d) ≤ ϕ(d).
d|(p−1) d|(p−1)
By Theorem 2.5, the sum on the right is p − 1, so the ≤ is an equality. Thus the inequalities
Np (d) ≤ ϕ(d) for all d dividing p−1 have to be equalities. In particular, Np (p−1) = ϕ(p−1),
which is positive, so there is an element of (Z/(p))× with order p − 1.
These orders are relatively prime, and the group is abelian, so the product g 3 h2 has order
25 · 9 > 96. Thus, 96 is not the maximal order in the group.
Now we return to the general case. If m does not divide n, then there is some prime
p whose multiplicity (exponent) as a factor of m exceeds that of n. Let pe be the highest
power of p in m and pf be the highest power of p in n, so e > f . (Quite possibly f = 0,
although in Example 3.2 both e and f were positive.)
f e
Now consider g p and hm/p . The first has order n/pf , which is not divisible by p, and
the second has order pe , which is a pure p-power. These orders are relatively prime. In an
abelian group, if g1 has order n1 and g2 has order n2 with (n1 , n2 ) = 1, then g1 g2 has order
f e
n1 n2 2 so g p hm/p has order
n e
p = npe−f > n.
pf
This contradicts the maximality of n as an order in G, so we have a contradiction.
The following theorem will be our criterion for showing a group is cyclic. Recall that in
a cyclic group there is just one subgroup of each size that occurs. Assuming the group is
abelian, the converse holds.
Theorem 3.3. Let G be a finite abelian group with at most one subgroup per size. Then G
is cyclic.
Proof. Let n be the maximal order among the elements of G, and let g ∈ G be an element
with order n. We will show every element of G is a power of g, so G = hgi.
Pick h ∈ G, and say h has order d. Since d | n by Lemma 3.1, we can write down
another element of order d: g n/d . Thus we have two subgroups of size d: hhi and hg n/d i.
By hypothesis, these subgroups are the same: hhi = hg n/d i. In particular, h ∈ hg n/d i ⊂ hgi,
so h is a power of g. Since h was arbitrary in G, G = hgi.
Remark 3.4. Is the abelian hypothesis in Theorem 3.3 necessary? That is, is there a
non-abelian group with at most one subgroup of each size? No. A finite group with at most
one subgroup of each size must be cyclic, even if we don’t assume at first that the group is
abelian. However, to prove this without an abelian hypothesis is quite a bit more involved
than the proof of Theorem 3.3. (Where did we use the abelian hypothesis in the proof of
Theorem 3.3?)
Now we are ready to show (Z/(p))× is cyclic.
Theorem 3.5. For each prime p, the group (Z/(p))× is cyclic.
Proof. We will show (Z/(p))× satisfies the hypothesis of Theorem 3.3: it has at most one
subgroup per size. Let H ⊂ (Z/(p))× be a subgroup, with size (say) d. Then every a ∈ H
satisfies ad = 1 in Z/(p), so H is a subset of the solutions to xd = 1. By Theorem 1.1, there
are at most d solutions to xd = 1 in Z/(p). Since d is the size of H (by definition), we filled
up the solutions of xd = 1 in Z/(p) using H:
H = {x ∈ Z/(p) : xd = 1}.
The right side is determined by d (and p), so there is at most one subgroup of (Z/(p))×
with size d, for each d. Thus Theorem 3.3 applies, which shows (Z/(p))× is cyclic.
2If we drop the condition (n , n ) = 1 then we can always say g g has order dividing [n , n ] since
1 2 1 2 1 2
[n ,n ] [n ,n ]
(g1 g2 )[n1 ,n2 ] = g1 1 2 g2 1 2 = 1, but [n1 , n2 ] is not a formula for the order of g1 g2 in general. For example,
if g has order n > 1 then g −1 has order n and gg −1 = 1 has order 1 while [n, n] = n > 1.
CYCLICITY OF (Z/(p))× 5
3See [Link]
subgroups-of-fields-are-cyclic.
6 KEITH CONRAD
so | ker f | ≤ a < n and | im f | ≤ b < n by Theorem 1.1. By induction, the subgroups ker f
and im f are cyclic. That means ker f = hhi and im f = hh0 i for some h and h0 in H.
By the first isomorphism theorem for groups we have H/ ker f ∼ = im f , so
|H| = | ker f || im f | ≤ ab = n = |H|.
Therefore the inequalities | ker f | ≤ a and | im f | ≤ b have to be equalities, so h has order a
and h0 has order b. Since (a, b) = 1 and h and h0 commute, by group theory hh0 has order
ab, which is |H|. Thus hh0 , which lies in H, is a generator of H, so H is cyclic.
By this inductive argument all subgroups of (Z/(p))× are cyclic, so (Z/(p))× is cyclic.
a mod 19 2 3 4 5 6 9 10 13 14 15 16 17
a6 mod 19 7 7 11 7 11 11 11 11 7 11 7 7
a2 mod 19 4 9 16 6 17 5 5 17 6 16 9 4
Remark 7.5. Lemma 7.3 can be proved in another way using unique factorization of
polynomials with coefficients in Z/(p). Because all nonzero numbers mod p are roots of
T p−1 − 1, this polynomial factors mod p as (T − 1)(T − 2) · · · (T − (p − 1)). Being a product
of distinct linear factors, every factor of T p−1 − 1 is also a product of distinct linear factors,
so in particular, every factor of T p−1 − 1 has as many roots in Z/(p) as its degree. For a
e e
prime power q e dividing p − 1, T q − 1 divides T p−1 − 1, so there are q e solutions of aq = 1
e−1
in Z/(p). This exceeds the number of solutions of aq = 1 in Z/(p), which is at most q e−1
since a nonzero polynomial over a field has no more roots than its degree. Therefore there
e e−1
is an a in Z/(p) fitting aq = 1 and aq 6= 1. All such a have order q e .
Theorem 7.6. For each prime p, the group (Z/(p))× is cyclic.
Proof. We may take p > 2, so p − 1 > 1. Write p − 1 as a product of primes:
p − 1 = q1e1 q2e2 · · · qm
em
.
By Lemma 7.3, for each i from 1 to m there is some bi in (Z/(p))× with order qiei . These
orders are relatively prime, and (Z/(p))× is abelian, so the product of the bi ’s has order
equal to the product of the qiei ’s, which is p − 1. Thus b1 b2 · · · bm generates (Z/(p))× .
Remark 7.7. The way we used Theorem 1.1 is that it tells us when p > 2 and 1 ≤ d < p−1,
there is a nonzero a mod p such that ad 6≡ 1 mod p. Christophe Bertault [2] pointed out
that the existence of such a can be proved without properties of polynomials, by using a
combinatorial argument. When m and n are positive P integers, the number of surjective
maps from an m-element set to an n-element set is nk=1 (−1)n−k nk k m , so when m < n we
have nk=1 (−1)n−k nk k m = 0. Therefore when p is an odd prime and d is a proper factor of
P
p − 1, p−1 p−1−k p−1 k d = 0. This implies k d 6≡ 1 mod p for some k ∈ {1, . . . , p − 1},
P
k=1 (−1) k
since otherwise p−1
P p−1−k p−1 k d ≡
Pp−1 k p−1 ≡ (1 − 1)p−1 − 1 ≡ −1 mod p,
k=1 (−1) k k=1 (−1) k
which contradicts the sum being 0 mod p.
Based on the proof of Theorem 7.6, here is a procedure to find a generator of (Z/(p))× :
(1) Get the prime factorization of p − 1, say p − 1 = q1e1 q2e2 · · · qm
em .
(p−1)/qi
(2) For each qi , find an ai such that ai 6≡ 1 mod p.
ei
(p−1)/q
(3) By Lemma 7.3, bi := ai i
mod p has order qiei in (Z/(p))× .
(4) The product b1 b2 · · · bm is a generator of (Z/(p))× .
Here’s an example.
Example 7.8. Take p = 3943, so p − 1 = 3942 = 2 · 33 · 73. We seek b1 of order 2, b2 of
order 27, and b3 of order 73. The product b1 b2 b3 mod p will have order p − 1.
• The first time a(p−1)/2 6≡ 1 mod p is at a = 3: 3(p−1)/2 ≡ 3942 ≡ −1 mod p. This
has order 2.
• The first time a(p−1)/3 6≡ 1 mod p is at a = 3: 3(p−1)/3 ≡ 1135 mod p. Then
3(p−1)/27 ≡ 2387 mod p has order 27.
• The first time a(p−1)/73 6≡ 1 mod p is at a = 2: 2(p−1)/73 ≡ 1406 mod p, which has
order 73.
CYCLICITY OF (Z/(p))× 9
instance, Q8 is not cyclic but it has only two solutions to x2 = 1. This is not a quirk about
Q8 : there are infinitely many non-abelian groups of 2-power order having only two solutions
to x2 = 1, such as the generalized quaternion groups Q2n for n ≥ 3.5
Theorem 8.3. For each prime p, the group (Z/(p))× is cyclic.
Proof. We may take p > 2, so p − 1 > 1. Write p − 1 = q1e1 q2e2 · · · qm
em , where the q ’s are
i
different primes (and each ei is positive). Set
ei
Ai = {a ∈ (Z/(p))× : aqi = 1}.
This is a subgroup of (Z/(p))× , and all of its elements have qi -power order, so |Ai | is a
power of qi by Cauchy’s theorem.
If Ai is not cyclic, then Theorem 8.1 says Ai has more than qi solutions to the equation
xqi = 1. However, we know this equation has no more than qi solutions in Z/(p) by Theorem
1.1. Thus we have reached a contradiction, so Ai is cyclic. (We do not yet know the order
of Ai , except that it is a qi -power. We may expect, though, that |Ai | = qiei .)
Write Ai = hai i. We are going to show a1 , a2 , . . . , am together generate (Z/(p))× . Then
we will show the single product a1 a2 · · · am is a generator of the group.
Dividing p − 1 by each of q1e1 , . . . , qm
em , we get the integers
6 T2 − T + 1
7 T + T + T4 + T3 + T2 + T + 1
6 5
8 T4 + 1
9 T + T3 + 1
6
10 T − T3 + T2 − T + 1
4
11 T + T + T + T 7 + T 6 + T 5 + T 4 + T 3 + T 2 + T + 1
10 9 8
12 T4 − T2 + 1
There are evidently a lot of patterns worth exploring here. For instance, Φ8 resembles
Φ4 , which resembles Φ2 , Φ10 is similar to Φ5 , and Φ12 seems related to Φ6 , which is close
to Φ3 . The constant term of Φn (T ), for n > 1, seems to be 1. Maybe the most striking
pattern, which persists for the first 100 cyclotomic polynomials, is that the coefficients are
all 0, 1, or −1. We will not determine whether or not this is always true (life needs some
12 KEITH CONRAD
tantalizing mysteries), but let’s show at least that all the coefficients are integers. First a
factorization lemma is needed.
Lemma 9.1. For n ≥ 1, T n − 1 = d|n Φd (T ).
Q
for some polynomial h(T ). Comparing degrees on both sides, we see h(T ) has degree 0,
so h(T ) is a constant. Now comparing leading coefficients on both sides, we must have
h(T ) = 1. Thus
Y
(9.3) Tn − 1 = (T − ρ),
ρn =1
Every n-th root of unity has some order dividing n. For each d dividing n, collect together
the linear factors T − ρ corresponding to roots of unity with order d. The product of these
factors is Φd (T ), by the definition of Φd (T ). Thus, we have transformed (9.3) into the
desired formula.
Example 9.2. Taking n = 4,
Y
Φd (T ) = Φ1 (T )Φ2 (T )Φ4 (T ) = (T − 1)(T + 1)(T 2 + 1) = T 4 − 1.
d|4
know about Φn (T ) is that it has complex coefficients. We want to deduce from (9.5) that
its coefficients are integers.
Let’s cook up a second divisibility relation between T n −1 and Bn (T ) in a completely dif-
ferent way: the usual division of (complex) polynomials, leaving a quotient and remainder.
We have
(9.6) T n − 1 = Bn (T )Q(T ) + R(T ),
where R(T ) = 0 or 0 ≤ deg R < deg Bn . When we divide one polynomial by another and
both have integer coefficients, the quotient and remainder may not have integer coefficients.
For instance,
2 1 1 5
T + 1 = (2T + 1) T− + .
2 4 4
However, if the divisor has leading coefficient 1, then everything stays integral, e.g., T 2 +1 =
(T + 1)(T − 1) + 2. Briefly, the source of all denominators in the quotient and remainder
comes from the leading coefficient of the divisor, so when it is 1, no denominators are
introduced. Thus, since Bn (T ) has integer coefficients and leading coefficient 1, Q(T ) and
R(T ) have integer coefficients.
We now compare our two relations (9.5) and (9.6). Since division of polynomials (with,
say, complex coefficients) has unique quotient and remainder, we must have Φn (T ) = Q(T )
and 0 = R(T ). In particular, since Q(T ) has integer coefficients, we have proved Φn (T ) has
integer coefficients!
Lemma 9.5. Working with coefficients in Z/(p), the polynomial T p−1 − 1 is a product of
linear factors:
T p−1 − 1 = (T − 1)(T − 2)(T − 3) · · · (T − (p − 1)).
Proof. For every a 6≡ 0 mod p, ap−1 ≡ 1 mod p, or ap−1 = 1 in Z/(p). Therefore the
polynomial T p−1 − 1, considered over Z/(p), has a as a root. Since a is a root, T − a is a
factor and the same reasoning used to get (9.2) implies
T p−1 − 1 = (T − 1)(T − 2)(T − 3) · · · (T − (p − 1))h(T )
for a polynomial h(T ). Comparing degrees and then leading coefficients on both sides,
h(T ) = 1.
Theorem 9.6. For each prime p, the group (Z/(p))× is cyclic.
Proof. Consider the factorization
Y
(9.7) T p−1 − 1 = Φd (T ).
d|(p−1)
All polynomials appearing here have integer coefficients. Collect the Φd (T ) with d 6= p − 1
into a single term:
(9.8) T p−1 − 1 = Φp−1 (T )H(T ),
where H(T ) has integer coefficients.
Reducing the coefficients in (9.8) modulo p lets us view (9.8) as a polynomial identity
over Z/(p). By Lemma 9.5, the left side of (9.8) breaks up into distinct linear factors over
Z/(p). Therefore, by unique factorization for polynomials with coefficients in Z/(p), the
two factors on the right side of (9.8) are products of linear polynomials over Z/(p) (as many
linear polynomials as the degree of the factor). Therefore Φp−1 (T ) has a root in Z/(p); in
14 KEITH CONRAD
fact, it has ϕ(p − 1) roots in Z/(p). We will show each a ∈ Z/(p) that is a root of Φp−1 (T ).
has order p − 1, so it is a generator of (Z/(p))× .
Since 0 is not a root of T p−1 − 1, a ∈ (Z/(p))× . Let d be the order of a in (Z/(p))× , so
d | p − 1. Could we have d < p − 1? Assume so. (We will get a contradiction and then we
will be done.) Since d is the order of a, ad − 1 = 0 in Z/(p). Now consider the factorization
of T d − 1 given by Lemma 9.1:
Y
Td − 1 = Φk (T ).
k|d
This identity between polynomials with integer coefficients can be viewed as an identity
between polynomials with coefficients in Z/(p) by reducing all the coefficients modulo p.
Setting T = a in this formula, the left side vanishes (in Z/(p)), so Φk (a) is 0 for some k
dividing d. (In fact, it is Φd (a) that vanishes, but we don’t need to know that.) Once Φk (a)
vanishes, Lemma A.2 tells us T − a is a factor of Φk (T ). Thus, in (9.7), T − a is a factor
twice: once in Φp−1 (T ) (that is how we defined a) and also as a factor in Φk (T ) for some k
dividing d. But the factorization of T p−1 − 1 in Lemma 9.5 has distinct linear factors. We
have a contradiction to unique factorization, so our assumption that d < p − 1 is in error:
d = p − 1, so a is a generator of (Z/(p))× .
Example 9.7. Taking p = 7, Φp−1 (T ) = Φ6 (T ) = T 2 − T + 1. Its roots in Z/(7) are 3
and 5: Φ6 (3) = 7 ≡ 0 mod 7 and Φ6 (5) = 21 ≡ 0 mod 7. The numbers 3 and 5 are the
generators of (Z/(7))× , as you can check directly.
Since
Remark A.3. There were two cases considered in the inductive step: when f (T ) has a root
in Z/(p) and when it does not. One of those cases must occur, but in an example we don’t
know which case occurs without searching for roots. This is why this proof of Theorem A.1
is not effective. It gives us an upper bound on the number of roots, but does not give us
the tools to decide if there is even one root in Z/(p) for a particular polynomial (of degree
greater than 1).
CYCLICITY OF (Z/(p))× 17
References
[1] M. Baker, Primitive roots, discrete logarithms, and p-adic numbers, [Link]
11/07/primitive-roots-discrete-logarithms-and-the-interplay-between-p-adic-and-complex-
numbers/.
[2] C. Bertault, “Une identité remarquable au service de (Z/pZ)∗ ,” Revue de Mathématiques Spéciales 131,
Jan. 2021. URL [Link]
[3] E. Bujalance Garcı́a, J. J. Etayo Gordejuela, and J. M. Gamboa Mutuberrı́a, Teorı́a Elemental de Grupos,
Univ. Nac. Educ. Distancia, Madrid, 2002.
[4] M. Bullynck, “Decimal periods and their tables: a German research topic (1765-1801),” URL https://
[Link]/halshs-00663295/document.
[5] L. Euler, “Demonstrationes circa residua ex divisione potestatum per numeros primos resultantia,” Novi
commentarii academiae scientiarum Petropolitanae 18 (1773), 85–135, 1774, Opera Omnia I, vol. 3,
240–281. URL [Link] and https://
[Link]/euler-works/449/.
[6] C. F. Gauss, Disquisitiones Arithmeticae, translated by Arthur A. Clarke, Yale Univ. Press, New Haven,
1966.
[7] J. H. Lambert, “Adnotata quaedam de numeris, eorumque anatomia,” Nova Acta Eruditorum (1769),
URL [Link]
[8] J. Rotman, Advanced Modern Algebra, 3rd ed., Part 1, Amer. Math. Soc., Providence, 2015.
[9] V. Shoup, A Computational Introduction to Number Theory and Algebra, 2nd edition, Cambridge Univ.
Press, 2008. URL [Link]