MATH2400 2,120 words·11 min read

Order and Primitive Elements

The Order of a Unit#

Recall that Zn∗\mathbb{Z}_n^* is the set of units of Zn\mathbb{Z}_n; the elements a∈Zna \in \mathbb{Z}_n with gcd⁡(a,n)=1\gcd(a,n) = 1, i.e. exactly the elements that have a multiplicative inverse. Recall also Euler's Theorem: for any a∈Zn∗a \in \mathbb{Z}_n^*,

aϕ(n)=1 in Zn.a^{\phi(n)} = 1 \text{ in } \mathbb{Z}_n.

So some power of every unit eventually equals 11; it is natural to ask for the first time this happens.

Note

Definition
Given any a∈Zn∗a \in \mathbb{Z}_n^* for n∈Z+n \in \mathbb{Z}^+, the order of aa, written ord⁡n(a)\operatorname{ord}_n(a), is the smallest positive integer kk such that ak=1a^k = 1 in Zn\mathbb{Z}_n.

Basically, the order of aa measures how long the powers a,a2,a3,…a, a^2, a^3, \dots take to first return to 11; after that point the powers just repeat the same cycle forever. Other notation for the order of a∈Zn∗a \in \mathbb{Z}_n^* includes ord⁡Zn(a)\operatorname{ord}_{\mathbb{Z}_n}(a), on(a)o_n(a) and ∣a∣|a|.

Be careful: "order" can mean something different depending on context; the order of a finite field FF sometimes refers to the number of elements in FF.

It is important to note that the order is only defined for units; if gcd⁡(a,n)≠1\gcd(a,n) \neq 1, then no power of aa ever reaches 11.

Example. Explain why ord⁡15(6)\operatorname{ord}_{15}(6) does not exist.
Notice that gcd⁡(6,15)=3≠1\gcd(6,15) = 3 \neq 1, so 6∉Z15∗6 \notin \mathbb{Z}_{15}^*. Watching the powers directly,

62=36=2×15+6=6 in Z15,\begin{align*} 6^2 &= 36 \\ &= 2 \times 15 + 6 \\ &= 6 \text{ in } \mathbb{Z}_{15}, \end{align*}

so every power of 66 collapses back to 66 itself and can never equal 11. More generally, 3∣6k3 \mid 6^k for every k∈Z+k \in \mathbb{Z}^+, but 3∤(15m+1)3 \nmid (15m + 1) for any mm; so 6k=16^k = 1 in Z15\mathbb{Z}_{15} is impossible. Therefore ord⁡15(6)\operatorname{ord}_{15}(6) does not exist; always check that aa is a unit before talking about its order.

Example. Find the orders of each of the elements in Z7∗\mathbb{Z}_7^*.
We previously found the power table for Z7∗\mathbb{Z}_7^*:

kk 11 22 33 44 55 66 77 …\dots
1k1^k 11 11 11 11 11 11 11 …\dots
2k2^k 22 44 11 22 44 11 22 …\dots
3k3^k 33 22 66 44 55 11 33 …\dots
4k4^k 44 22 11 44 22 11 44 …\dots
5k5^k 55 44 66 22 33 11 55 …\dots
6k6^k 66 11 66 11 66 11 66 …\dots

Reading along each row until the first 11 appears,

ord⁡7(1)=1,ord⁡7(2)=3,ord⁡7(3)=6,ord⁡7(4)=3,ord⁡7(5)=6,ord⁡7(6)=2.\begin{align*} \operatorname{ord}_7(1) &= 1, \\ \operatorname{ord}_7(2) &= 3, \\ \operatorname{ord}_7(3) &= 6, \\ \operatorname{ord}_7(4) &= 3, \\ \operatorname{ord}_7(5) &= 6, \\ \operatorname{ord}_7(6) &= 2. \end{align*}

Notice how every order that shows up (1,2,31, 2, 3 and 66) is a divisor of 6=ϕ(7)6 = \phi(7); this is not a coincidence, as we are about to see.

Order Divides the Totient#

Before the main theorem, we need a small lemma that describes exactly which powers of a unit equal 11.

Note

Lemma
For any a∈Zn⋆a \in \mathbb{Z}_n^\star and k∈Nk\in\mathbb{N}, we have ak=1a^k = 1 in Zn\mathbb{Z}_n if and only if ord⁡n(a)∣k\operatorname{ord}_n(a) \mid k.

Proof. Let d=ord⁡n(a)d = \operatorname{ord}_n(a).
(⇐\Leftarrow) Suppose d∣kd \mid k; then k=dqk = dq for some q∈Nq \in \mathbb{N}, so

ak=adq=(ad)q=1q=1 in Zn.\begin{align*} a^k &= a^{dq} \\ &= (a^d)^q \\ &= 1^q \\ &= 1 \text{ in } \mathbb{Z}_n. \end{align*}

(⇒\Rightarrow) Suppose ak=1a^k = 1. By the Division Theorem we can write k=qd+rk = qd + r with 0≤r<d0 \leq r < d, so

1=ak=(ad)q ar=1q ar=ar.\begin{align*} 1 &= a^k \\ &= (a^d)^q \, a^r \\ &= 1^q \, a^r \\ &= a^r. \end{align*}

But dd is the smallest positive exponent giving 11, and r<dr < d; the only way out is r=0r = 0. Hence k=qdk = qd; that is, d∣kd \mid k. ■\blacksquare

Basically, the powers of aa hit 11 at d,2d,3d,…d, 2d, 3d, \dots and nowhere else; the sequence of powers is periodic with period exactly ord⁡n(a)\operatorname{ord}_n(a). Since aa is invertible, ai=aja^i = a^j (for i≥ji \geq j) is the same as ai−j=1a^{i-j} = 1, which gives a fact worth boxing:

ai=aj in Zn  ⟺  i≡j(modord⁡n(a)).\boxed{a^i = a^j \text{ in } \mathbb{Z}_n \iff i \equiv j \pmod{\operatorname{ord}_n(a)}.}

Note

Theorem
For any a∈Zn⋆a \in \mathbb{Z}_n^\star, we have that ord⁡n(a)∣ϕ(n)\operatorname{ord}_n(a) \mid \phi(n).
Proof. By Euler's Theorem, aϕ(n)=1a^{\phi(n)} = 1 in Zn\mathbb{Z}_n; so by the Lemma above, ord⁡n(a)∣ϕ(n)\operatorname{ord}_n(a) \mid \phi(n). ■\blacksquare

This theorem is what makes computing orders fast. Instead of grinding through a,a2,a3,…a, a^2, a^3, \dots one power at a time, you only ever need to test the exponents kk that divide ϕ(n)\phi(n); the order must be one of those divisors, and it is the smallest one that works.

Example. Find ord⁡15(7)\operatorname{ord}_{15}(7).
First, ϕ(15)=ϕ(3)ϕ(5)=2×4=8\phi(15) = \phi(3)\phi(5) = 2 \times 4 = 8, so ord⁡15(7)∈{1,2,4,8}\operatorname{ord}_{15}(7) \in \{1, 2, 4, 8\}. Testing the divisors in increasing order,

71=7≠1,72=49=3×15+4=4≠1,74=(72)2=42=16=1 in Z15.\begin{align*} 7^1 &= 7 \neq 1, \\ 7^2 &= 49 \\ &= 3 \times 15 + 4 \\ &= 4 \neq 1, \\ 7^4 &= (7^2)^2 \\ &= 4^2 \\ &= 16 \\ &= 1 \text{ in } \mathbb{Z}_{15}. \end{align*}

Therefore, ord⁡15(7)=4\operatorname{ord}_{15}(7) = 4.

Example. Find ord⁡18(5)\operatorname{ord}_{18}(5).
Here ϕ(18)=ϕ(2)ϕ(9)=1×6=6\phi(18) = \phi(2)\phi(9) = 1 \times 6 = 6, so the order is one of 1,2,3,61, 2, 3, 6. Testing,

51=5≠1,52=25=7≠1,53=5×7=35=17=−1≠1 in Z18.\begin{align*} 5^1 &= 5 \neq 1, \\ 5^2 &= 25 \\ &= 7 \neq 1, \\ 5^3 &= 5 \times 7 \\ &= 35 \\ &= 17 \\ &= -1 \neq 1 \text{ in } \mathbb{Z}_{18}. \end{align*}

Every proper divisor of 66 has failed, so the order is forced to be ϕ(18)\phi(18) itself; we do not even need to compute 565^6, since Euler's Theorem already guarantees 56=15^6 = 1. Therefore, ord⁡18(5)=6\operatorname{ord}_{18}(5) = 6.

Notice how landing on −1-1 was a bonus; once you see ak=−1a^k = -1, you immediately know a2k=1a^{2k} = 1, and that no smaller multiple of kk can give 11 along that chain. Keep an eye out for −1-1; it saves a lot of arithmetic.

Example. Find 720267^{2026} in Z15\mathbb{Z}_{15}.
From earlier, ord⁡15(7)=4\operatorname{ord}_{15}(7) = 4, so the powers of 77 repeat with period 44; we only care about 20262026 modulo the order:

2026=4×506+2,72026=(74)506×72=1506×4=4 in Z15.\begin{align*} 2026 &= 4 \times 506 + 2, \\ 7^{2026} &= (7^4)^{506} \times 7^2 \\ &= 1^{506} \times 4 \\ &= 4 \text{ in } \mathbb{Z}_{15}. \end{align*}

Therefore, 72026=47^{2026} = 4 in Z15\mathbb{Z}_{15}. You could also have reduced the exponent modulo ϕ(15)=8\phi(15) = 8 (Euler), but the order gives the tightest possible reduction. Reduce the exponent modulo the order, never modulo nn; 2026≡1(mod15)2026 \equiv 1 \pmod{15} tells you nothing about 720267^{2026}.

Primitive Elements#

Since the order of a unit always divides ϕ(n)\phi(n), the largest an order can possibly be is ϕ(n)\phi(n) itself. The units that actually achieve this maximum get a special name.

Note

Definition
For any n∈Z+n \in \mathbb{Z}^+, a primitive element of Zn∗\mathbb{Z}_n^* (or a primitive root modulo nn) is any element a∈Zn∗a \in \mathbb{Z}_n^* such that ord⁡n(a)=ϕ(n)\operatorname{ord}_n(a) = \phi(n).

Basically, a primitive element is a unit whose powers take the longest possible route before cycling back to 11; as we will see shortly, its powers visit every unit along the way.

Example. The primitive elements of Z7∗\mathbb{Z}_7^* are 33 and 55, since we saw in the order table that ord⁡7(3)=ord⁡7(5)=6=ϕ(7)\operatorname{ord}_7(3) = \operatorname{ord}_7(5) = 6 = \phi(7).

Example. What are the primitive elements of Z6∗\mathbb{Z}_6^*?
Here Z6∗={1,5}\mathbb{Z}_6^* = \{1, 5\} and ϕ(6)=2\phi(6) = 2. Clearly ord⁡6(1)=1≠2\operatorname{ord}_6(1) = 1 \neq 2, and

52=25=4×6+1=1 in Z6,\begin{align*} 5^2 &= 25 \\ &= 4 \times 6 + 1 \\ &= 1 \text{ in } \mathbb{Z}_6, \end{align*}

so ord⁡6(5)=2=ϕ(6)\operatorname{ord}_6(5) = 2 = \phi(6). Therefore, the only primitive element of Z6∗\mathbb{Z}_6^* is 55.

Example. What are the primitive elements of Z8∗\mathbb{Z}_8^*?
Here Z8∗={1,3,5,7}\mathbb{Z}_8^* = \{1, 3, 5, 7\} and ϕ(8)=4\phi(8) = 4. Squaring each unit,

32=9=1 in Z8,52=25=1 in Z8,72=49=1 in Z8,\begin{align*} 3^2 &= 9 = 1 \text{ in } \mathbb{Z}_8, \\ 5^2 &= 25 = 1 \text{ in } \mathbb{Z}_8, \\ 7^2 &= 49 = 1 \text{ in } \mathbb{Z}_8, \end{align*}

so every unit other than 11 has order 22, and ord⁡8(1)=1\operatorname{ord}_8(1) = 1; no element has order ϕ(8)=4\phi(8) = 4. Therefore, Z8∗\mathbb{Z}_8^* has no primitive elements. Not every Zn∗\mathbb{Z}_n^* has a primitive element; never assume one exists without checking.

Primitive Elements as Generators#

Note

Notation
For any element aa of a finite group, the (cyclic) group generated by aa is written ⟨a⟩\langle a \rangle and given by ⟨a⟩={a0,a1,a2,a3,… }\langle a \rangle = \{a^0, a^1, a^2, a^3, \dots\}.

Note

Theorem
If aa is a primitive element of Zn⋆\mathbb{Z}_n^\star, then

⟨a⟩={a0,a1,a2,…,aϕ(n)−1}=Zn∗.\langle a \rangle = \{a^0, a^1, a^2, \dots, a^{\phi(n)-1}\} = \mathbb{Z}_n^*.

Proof. Each power aka^k is a product of units and hence a unit, so ⟨a⟩⊆Zn∗\langle a \rangle \subseteq \mathbb{Z}_n^*. Now suppose two of the listed powers were equal; say ai=aja^i = a^j with 0≤i<j≤ϕ(n)−10 \leq i < j \leq \phi(n) - 1. Since aa is invertible, we can multiply both sides by (ai)−1(a^i)^{-1} to get

aj−i=1,where 0<j−i<ϕ(n).\begin{align*} a^{j-i} &= 1, \quad \text{where } 0 < j - i < \phi(n). \end{align*}

But aa is primitive, so ord⁡n(a)=ϕ(n)\operatorname{ord}_n(a) = \phi(n); there is no positive exponent smaller than ϕ(n)\phi(n) giving 11, which is a contradiction. Hence the powers a0,a1,…,aϕ(n)−1a^0, a^1, \dots, a^{\phi(n)-1} are ϕ(n)\phi(n) distinct elements of Zn∗\mathbb{Z}_n^*; and since Zn∗\mathbb{Z}_n^* only has ϕ(n)\phi(n) elements in total, the two sets must be equal. ■\blacksquare

Basically, a primitive element generates the whole unit group; every single unit mod nn is some power of aa. This is exactly why primitive elements are so useful: one element single-handedly produces everything.

For example, the first six powers of either primitive element of Z7∗\mathbb{Z}_7^* sweep out all of Z7∗\mathbb{Z}_7^*; all six units appear in the rows for 33 and 55:

kk 11 22 33 44 55 66 …\dots
3k3^k 33 22 66 44 55 11 …\dots
5k5^k 55 44 66 22 33 11 …\dots

Contrast this with 22, which is not primitive; its powers 2,4,1,2,4,1,…2, 4, 1, 2, 4, 1, \dots only ever produce {1,2,4}\{1, 2, 4\}, i.e. ⟨2⟩≠Z7∗\langle 2 \rangle \neq \mathbb{Z}_7^*.

Multiplication with Primitive Elements#

In Zp\mathbb{Z}_p for any prime pp, we can use the fact that the powers of a primitive element generate Zp∗\mathbb{Z}_p^* to build a method for multiplication in Zp\mathbb{Z}_p that is very time-efficient for very large pp.

Suppose we know aa is a primitive element of Zp∗\mathbb{Z}_p^* and have recorded the powers of aa in a lookup table. Then we can multiply two numbers x,y∈Zp∗x, y \in \mathbb{Z}_p^* as follows:

  • Use the lookup table to find ii and jj such that x=aix = a^i and y=ajy = a^j in Zp\mathbb{Z}_p.
  • Calculate (i+j) mod (p−1)(i + j) \bmod (p-1).
  • Use the lookup table to find a(i+j) mod (p−1)=xya^{(i+j) \bmod (p-1)} = xy in Zp\mathbb{Z}_p.

The reason we reduce the exponent mod p−1p - 1 is that ord⁡p(a)=ϕ(p)=p−1\operatorname{ord}_p(a) = \phi(p) = p - 1, so by our boxed fact the exponents only matter modulo p−1p - 1. The efficiency of this method for large pp (and x,yx,y) comes from the fact that the only calculation required is addition, which is computationally much cheaper than multiplication; this is basically how logarithm tables worked before calculators, with ii playing the role of log⁡a(x)\log_a(x).

Example. Given the powers of 22 in Z11\mathbb{Z}_{11}, find 5×105 \times 10 and 7×97 \times 9 in Z11\mathbb{Z}_{11}.

kk 11 22 33 44 55 66 77 88 99 1010
2k2^k 22 44 88 55 1010 99 77 33 66 11

For 5×105 \times 10: from the table, 5=245 = 2^4 and 10=2510 = 2^5, so

5×10=24×25=2(4+5) mod 10=29=6 in Z11.\begin{align*} 5 \times 10 &= 2^4 \times 2^5 \\ &= 2^{(4+5) \bmod 10} \\ &= 2^9 \\ &= 6 \text{ in } \mathbb{Z}_{11}. \end{align*}

For 7×97 \times 9: from the table, 7=277 = 2^7 and 9=269 = 2^6, so

7×9=27×26=213 mod 10=23=8 in Z11.\begin{align*} 7 \times 9 &= 2^7 \times 2^6 \\ &= 2^{13 \bmod 10} \\ &= 2^3 \\ &= 8 \text{ in } \mathbb{Z}_{11}. \end{align*}

As a sanity check, 50=4×11+650 = 4 \times 11 + 6 and 63=5×11+863 = 5 \times 11 + 8; both answers agree with direct computation.

The lookup table also lets you run this machine in reverse, which is exactly a discrete logarithm.

Example. Find all x∈Zx \in \mathbb{Z} such that 2x=72^x = 7 in Z11\mathbb{Z}_{11}.
From the table, 27=72^7 = 7; and since the powers of 22 repeat with period ord⁡11(2)=10\operatorname{ord}_{11}(2) = 10, we have 2x=272^x = 2^7 if and only if x≡7(mod10)x \equiv 7 \pmod{10}. Therefore, the solutions are exactly x≡7(mod10)x \equiv 7 \pmod{10}.

Example. Solve x4=5x^4 = 5 in Z11\mathbb{Z}_{11}.
Every non-zero element of Z11\mathbb{Z}_{11} is a power of the primitive element 22, so write x=2tx = 2^t; from the table 5=245 = 2^4. The equation becomes

24t=244t≡4(mod10)2t≡2(mod5)t≡1(mod5),\begin{align*} 2^{4t} &= 2^4 \\ 4t &\equiv 4 \pmod{10} \\ 2t &\equiv 2 \pmod{5} \\ t &\equiv 1 \pmod 5, \end{align*}

where we divided the congruence (and the modulus) by gcd⁡(4,10)=2\gcd(4,10) = 2, then multiplied by the inverse of 22 mod 55. So t∈{1,6}t \in \{1, 6\} modulo 1010, giving

x=21=2,x=26=9 in Z11.\begin{align*} x &= 2^1 = 2, \\ x &= 2^6 = 9 \text{ in } \mathbb{Z}_{11}. \end{align*}

Checking: 92=81=49^2 = 81 = 4 and 42=16=54^2 = 16 = 5 in Z11\mathbb{Z}_{11}. Therefore, the solutions are x=2x = 2 and x=9x = 9. Notice how the primitive element converted a nasty power equation into a linear congruence in the exponent; this is the standard trick for equations of the form xk=bx^k = b in Zp\mathbb{Z}_p.

Which Unit Groups Have Primitive Elements#

We saw that Z8∗\mathbb{Z}_8^* has no primitive element, so existence is a genuine question. Fortunately there is a complete answer.

Note

Theorem
The unit group Zn⋆\mathbb{Z}_n^\star has a primitive element if and only if nn is equal to 11, 22, 44, pkp^k, or 2pk2p^k, where pp is any odd prime and k∈Z+k \in \mathbb{Z}^+.

The proof of this one is apparently quite complicated so it's omitted for this course; these questions are just pattern matching against the list. In particular, every prime modulus has a primitive root, which is why the multiplication trick above always works in Zp\mathbb{Z}_p.

Example. Do each of the following groups of units have primitive elements?

  • Z10∗\mathbb{Z}_{10}^*: here 10=2×5=2pk10 = 2 \times 5 = 2p^k with p=5p = 5, k=1k = 1; so yes. (Indeed 33 works: its powers in Z10\mathbb{Z}_{10} are 3,9,7,13, 9, 7, 1, so ord⁡10(3)=4=ϕ(10)\operatorname{ord}_{10}(3) = 4 = \phi(10).)
  • Z35∗\mathbb{Z}_{35}^*: here 35=5×735 = 5 \times 7 is a product of two distinct odd primes, which is not on the list; so no.
  • Z343∗\mathbb{Z}_{343}^*: here 343=73=pk343 = 7^3 = p^k; so yes.

Example. Show directly that Z12∗\mathbb{Z}_{12}^* has no primitive element.
Since 12=22×312 = 2^2 \times 3 is not of any of the allowed forms, the theorem says no; but it is worth seeing this happen by hand. We have Z12∗={1,5,7,11}\mathbb{Z}_{12}^* = \{1, 5, 7, 11\} and ϕ(12)=4\phi(12) = 4, and

52=25=1 in Z12,72=49=1 in Z12,112=121=1 in Z12,\begin{align*} 5^2 &= 25 = 1 \text{ in } \mathbb{Z}_{12}, \\ 7^2 &= 49 = 1 \text{ in } \mathbb{Z}_{12}, \\ 11^2 &= 121 = 1 \text{ in } \mathbb{Z}_{12}, \end{align*}

so every unit has order at most 2<42 < 4. This is the same behaviour as Z8∗\mathbb{Z}_8^*; everything squares to 11, so no single element can generate all four units.

Finding a Primitive Element#

In general, there is no known efficient method to find a primitive element of Zn∗\mathbb{Z}_n^*. The method we use (inefficient, but fine by hand) is:

  • Choose aa to be a small element of Zn∗\mathbb{Z}_n^*, taking candidates from the list of numbers that are not pure powers: 2,3,5,6,7,10,11,…2, 3, 5, 6, 7, 10, 11, \dots in order.
  • For each prime divisor pip_i of ϕ(n)\phi(n), compute aϕ(n)/pia^{\phi(n)/p_i} in Zn\mathbb{Z}_n.
  • If aϕ(n)/pi≠1a^{\phi(n)/p_i} \neq 1 in Zn\mathbb{Z}_n for all prime divisors pip_i of ϕ(n)\phi(n), then (and only then) aa is a primitive element of Zn∗\mathbb{Z}_n^*.

The reason this works comes back to order dividing the totient. If ord⁡n(a)≠ϕ(n)\operatorname{ord}_n(a) \neq \phi(n), then ord⁡n(a)\operatorname{ord}_n(a) is a proper divisor of ϕ(n)\phi(n); its prime factorisation must be missing at least one copy of some prime divisor pip_i of ϕ(n)\phi(n), so ord⁡n(a)∣ϕ(n)/pi\operatorname{ord}_n(a) \mid \phi(n)/p_i, and hence aϕ(n)/pi=1a^{\phi(n)/p_i} = 1 by the Lemma. Conversely, if aa is primitive then no exponent smaller than ϕ(n)\phi(n) can give 11. So testing just those few exponents ϕ(n)/pi\phi(n)/p_i detects primitivity exactly; you never have to check every divisor of ϕ(n)\phi(n).

We skip pure powers like 4,8,94, 8, 9 in the candidate list because they can never succeed after their base has failed; if 4=224 = 2^2 were primitive, then ord⁡n(2)\operatorname{ord}_n(2) would already have to be ϕ(n)\phi(n) (a power of 22 can't cycle for longer than 22 does), so 22 would have been primitive first.

Example. Find a primitive element of Z31∗\mathbb{Z}_{31}^*.
Here ϕ(31)=30=2×3×5\phi(31) = 30 = 2 \times 3 \times 5, so the exponents to test are

302=15,303=10,305=6.\frac{30}{2} = 15, \quad \frac{30}{3} = 10, \quad \frac{30}{5} = 6.

Candidate a=2a = 2:

25=32=1 in Z31,215=(25)3=1 in Z31,\begin{align*} 2^5 &= 32 \\ &= 1 \text{ in } \mathbb{Z}_{31}, \\ 2^{15} &= (2^5)^3 \\ &= 1 \text{ in } \mathbb{Z}_{31}, \end{align*}

so 22 fails the test (in fact ord⁡31(2)=5\operatorname{ord}_{31}(2) = 5) and is not primitive.
Candidate a=3a = 3: first note 35=243=7×31+26=26=−53^5 = 243 = 7 \times 31 + 26 = 26 = -5 in Z31\mathbb{Z}_{31}, then

36=35×3=−15=16≠1,310=(35)2=(−5)2=25≠1,315=310×35=25×(−5)=−125=−1≠1 in Z31,\begin{align*} 3^6 &= 3^5 \times 3 \\ &= -15 \\ &= 16 \neq 1, \\ 3^{10} &= (3^5)^2 \\ &= (-5)^2 \\ &= 25 \neq 1, \\ 3^{15} &= 3^{10} \times 3^5 \\ &= 25 \times (-5) \\ &= -125 \\ &= -1 \neq 1 \text{ in } \mathbb{Z}_{31}, \end{align*}

since −125+4×31=−1-125 + 4 \times 31 = -1. All three tests pass; therefore 33 is a primitive element of Z31∗\mathbb{Z}_{31}^*. Notice how writing 2626 as −5-5 made every one of these computations painless; working with small negative representatives is almost always faster than working with large positive ones.

Finding All Primitive Elements#

Once you have found one primitive element, you get all the others essentially for free.

Note

Theorem
Given aa is a primitive element of Zn⋆\mathbb{Z}_n^\star, we have that aka^k is a primitive element of Zn⋆\mathbb{Z}_n^\star if and only if gcd⁡(k,ϕ(n))=1\gcd(k, \phi(n)) = 1.

Proof. Let g=gcd⁡(k,ϕ(n))g = \gcd(k, \phi(n)) and let m=ord⁡n(ak)m = \operatorname{ord}_n(a^k). Since ord⁡n(a)=ϕ(n)\operatorname{ord}_n(a) = \phi(n), the Lemma from earlier gives

(ak)m=akm=1  ⟺  ϕ(n)∣km.(a^k)^m = a^{km} = 1 \iff \phi(n) \mid km.

Dividing both ϕ(n)\phi(n) and kk by gg, this is equivalent to ϕ(n)g∣kgm\frac{\phi(n)}{g} \mid \frac{k}{g}m; and since gcd⁡ ⁣(ϕ(n)g,kg)=1\gcd\!\left(\frac{\phi(n)}{g}, \frac{k}{g}\right) = 1, this happens exactly when ϕ(n)g∣m\frac{\phi(n)}{g} \mid m. The smallest positive such mm is ϕ(n)g\frac{\phi(n)}{g}, so

ord⁡n(ak)=ϕ(n)gcd⁡(k,ϕ(n)),\operatorname{ord}_n(a^k) = \frac{\phi(n)}{\gcd(k, \phi(n))},

which equals ϕ(n)\phi(n) precisely when gcd⁡(k,ϕ(n))=1\gcd(k, \phi(n)) = 1. ■\blacksquare

The exact same argument works with ϕ(n)\phi(n) replaced by the order of any unit, giving a formula that is genuinely worth memorising:

ord⁡n(ak)=ord⁡n(a)gcd⁡(k,ord⁡n(a)).\boxed{\operatorname{ord}_n(a^k) = \frac{\operatorname{ord}_n(a)}{\gcd(k, \operatorname{ord}_n(a))}.}

Basically, raising aa to the power kk shrinks its cycle by exactly the factor gcd⁡(k,ord⁡n(a))\gcd(k, \operatorname{ord}_n(a)); if kk shares no factors with the order, the cycle length is untouched.

Note

Corollary
If aa is a primitive element of Zn∗\mathbb{Z}_n^*, then the complete set of all primitive elements in Zn∗\mathbb{Z}_n^* is given by {ak:k∈Zϕ(n)∗}\{a^k : k \in \mathbb{Z}_{\phi(n)}^*\}.

Note

Corollary
If Zn∗\mathbb{Z}_n^* has a primitive element, then altogether Zn∗\mathbb{Z}_n^* has exactly ∣Zϕ(n)∗∣=ϕ(ϕ(n))|\mathbb{Z}_{\phi(n)}^*| = \phi(\phi(n)) primitive elements.

If Zn∗ has a primitive element, it has exactly ϕ(ϕ(n)) of them.\boxed{\text{If } \mathbb{Z}_n^* \text{ has a primitive element, it has exactly } \phi(\phi(n)) \text{ of them.}}

This matches everything we have seen so far: Z6∗\mathbb{Z}_6^* has 11 primitive element (55) and ϕ(ϕ(6))=ϕ(2)=1\phi(\phi(6)) = \phi(2) = 1, while Z7∗\mathbb{Z}_7^* has 22 primitive elements (33 and 55) and ϕ(ϕ(7))=ϕ(6)=2\phi(\phi(7)) = \phi(6) = 2.

Example. Given 22 is a primitive element of Z9∗\mathbb{Z}_9^*, find all the primitive elements of Z9∗\mathbb{Z}_9^*.
Here ϕ(9)=9−3=6\phi(9) = 9 - 3 = 6, and Z6∗={1,5}\mathbb{Z}_6^* = \{1, 5\}; so by the corollary, the primitive elements are exactly 212^1 and 252^5:

21=2,25=32=3×9+5=5 in Z9.\begin{align*} 2^1 &= 2, \\ 2^5 &= 32 \\ &= 3 \times 9 + 5 \\ &= 5 \text{ in } \mathbb{Z}_9. \end{align*}

Therefore, the primitive elements of Z9∗\mathbb{Z}_9^* are 22 and 55; as a check, ϕ(ϕ(9))=ϕ(6)=2\phi(\phi(9)) = \phi(6) = 2 elements, as expected.

Example. Find all primitive elements of Z31∗\mathbb{Z}_{31}^*.
From the previous section, 33 is a primitive element of Z31∗\mathbb{Z}_{31}^* and ϕ(31)=30\phi(31) = 30. The units mod 30=2×3×530 = 2 \times 3 \times 5 are the numbers coprime to 22, 33 and 55:

Z30∗={1,7,11,13,17,19,23,29},\mathbb{Z}_{30}^* = \{1, 7, 11, 13, 17, 19, 23, 29\},

which has ϕ(30)=ϕ(2)ϕ(3)ϕ(5)=1×2×4=8\phi(30) = \phi(2)\phi(3)\phi(5) = 1 \times 2 \times 4 = 8 elements; so there are exactly 88 primitive elements, namely 3k3^k for each k∈Z30∗k \in \mathbb{Z}_{30}^*. First tabulate the powers of 33 up to 315=−13^{15} = -1:

kk 11 22 33 44 55 66 77 88 99 1010 1111 1212 1313 1414 1515
3k3^k 33 99 2727 1919 2626 1616 1717 2020 2929 2525 1313 88 2424 1010 3030

The exponents up to 1515 can be read straight off the table, and since 315=−13^{15} = -1, every later power is just the negative of an earlier one; 315+j=−3j3^{15+j} = -3^j:

31=3,37=17,311=13,313=24,317=−32=−9=22,319=−34=−19=12,323=−38=−20=11,329=−314=−10=21 in Z31.\begin{align*} 3^1 &= 3, \\ 3^7 &= 17, \\ 3^{11} &= 13, \\ 3^{13} &= 24, \\ 3^{17} &= -3^2 = -9 = 22, \\ 3^{19} &= -3^4 = -19 = 12, \\ 3^{23} &= -3^8 = -20 = 11, \\ 3^{29} &= -3^{14} = -10 = 21 \text{ in } \mathbb{Z}_{31}. \end{align*}

Therefore, the primitive elements of Z31∗\mathbb{Z}_{31}^* are

{3,11,12,13,17,21,22,24},\{3, 11, 12, 13, 17, 21, 22, 24\},

and there are 8=ϕ(ϕ(31))8 = \phi(\phi(31)) of them, as expected.

Example. Construct the full order table for Z13∗\mathbb{Z}_{13}^* and hence find all primitive elements of Z13∗\mathbb{Z}_{13}^*.
The lazy way is to compute the whole 12×1212 \times 12 power table; the smart way is to find one primitive element and then use the boxed formula for ord⁡n(ak)\operatorname{ord}_n(a^k).

First, ϕ(13)=12=22×3\phi(13) = 12 = 2^2 \times 3, so the prime divisors of ϕ(13)\phi(13) are 22 and 33 and we test the exponents 122=6\frac{12}{2} = 6 and 123=4\frac{12}{3} = 4. Trying a=2a = 2:

24=16=3≠1,26=64=12=−1≠1 in Z13,\begin{align*} 2^4 &= 16 \\ &= 3 \neq 1, \\ 2^6 &= 64 \\ &= 12 \\ &= -1 \neq 1 \text{ in } \mathbb{Z}_{13}, \end{align*}

so 22 is a primitive element of Z13∗\mathbb{Z}_{13}^*. Its powers are:

kk 11 22 33 44 55 66 77 88 99 1010 1111 1212
2k2^k 22 44 88 33 66 1212 1111 99 55 1010 77 11

Every unit a∈Z13∗a \in \mathbb{Z}_{13}^* is 2k2^k for exactly one k∈{1,…,12}k \in \{1, \dots, 12\}, and

ord⁡13(2k)=12gcd⁡(k,12).\operatorname{ord}_{13}(2^k) = \frac{12}{\gcd(k, 12)}.

For instance 9=289 = 2^8, so ord⁡13(9)=12gcd⁡(8,12)=124=3\operatorname{ord}_{13}(9) = \frac{12}{\gcd(8,12)} = \frac{12}{4} = 3; checking, 93=729=56×13+1=19^3 = 729 = 56 \times 13 + 1 = 1 in Z13\mathbb{Z}_{13}. Running through every kk gives the complete order table:

aa 11 22 33 44 55 66 77 88 99 1010 1111 1212
ord⁡13(a)\operatorname{ord}_{13}(a) 11 1212 33 66 44 1212 1212 44 33 66 1212 22

The primitive elements are the units of order 1212; therefore the primitive elements of Z13∗\mathbb{Z}_{13}^* are

{2,6,7,11},\{2, 6, 7, 11\},

and indeed ϕ(ϕ(13))=ϕ(12)=4\phi(\phi(13)) = \phi(12) = 4 of them. Notice also how every order in the table is a divisor of 1212, and for each divisor dd of 1212 the number of elements of order dd is exactly ϕ(d)\phi(d):

d=1:{1},ϕ(1)=1,d=2:{12},ϕ(2)=1,d=3:{3,9},ϕ(3)=2,d=4:{5,8},ϕ(4)=2,d=6:{4,10},ϕ(6)=2,d=12:{2,6,7,11},ϕ(12)=4.\begin{align*} d = 1 &: \{1\}, &\phi(1) &= 1, \\ d = 2 &: \{12\}, &\phi(2) &= 1, \\ d = 3 &: \{3, 9\}, &\phi(3) &= 2, \\ d = 4 &: \{5, 8\}, &\phi(4) &= 2, \\ d = 6 &: \{4, 10\}, &\phi(6) &= 2, \\ d = 12 &: \{2, 6, 7, 11\}, &\phi(12) &= 4. \end{align*}

This pattern holds whenever a primitive element exists; it is a handy sanity check that your order computations are consistent, since the counts have to add up to ϕ(n)\phi(n).