Number TheoryOrders and Primitive Roots

Primitive Roots

g is a primitive root mod p when its order is p − 1, so its powers reach every nonzero residue; check that g^((p − 1)/q) ≢ 1 for each prime q dividing p − 1.

Not started Jump to practice

Some numbers have the largest order possible. Mod 7, the powers of 3 are $3, 2, 6, 4, 5, 1$: every nonzero residue appears once. Such a number turns multiplication mod $p$ into addition of exponents, and that is the foundation of discrete logarithms and Diffie–Hellman.

Definition. $g$ is a primitive root mod $n$ when $\operatorname{ord}_n(g) = \varphi(n)$. Mod a prime $p$ this means order $p - 1$, so $g, g^{2}, \dots, g^{p-1}$ are all the nonzero residues, each exactly once.

Theorem (Gauss). Every prime $p$ has a primitive root; in fact it has exactly $\varphi(p - 1)$ of them. (Among other moduli, only $1, 2, 4, p^{k}$ and $2p^{k}$ have primitive roots; mod 8, for instance, every unit has order 1 or 2.)

The test. Let $q_1, \dots, q_s$ be the primes dividing $p - 1$. Then $g$ is a primitive root mod $p$ exactly when $$g^{(p-1)/q_i} \not\equiv 1 \pmod{p} \quad\text{for every } i.$$

Why it works

The order of $g$ divides $p - 1$. If it is smaller than $p - 1$, it is a proper divisor, so some prime $q_i$ is "missing" from it, and the order divides $(p - 1)/q_i$. Then $g^{(p-1)/q_i} \equiv 1$. So if none of these powers is 1, the order can only be $p - 1$. This needs a few powers instead of $p - 1$ of them.
All powers mod 13. Every row reaches 1 at $k = 12$; the first 1 in each row is its order (1, 2, 3, 4, 6 or 12). The starred rows, 2, 6, 7 and 11, contain every unit: $\varphi(12) = 4$ primitive roots.

Worked example: A primitive root

Is $2$ a primitive root mod $11$?
  1. $p - 1 = 10 = 2 \cdot 5$, so check $2^{10/2} = 2^{5}$ and $2^{10/5} = 2^{2}$.
  2. $2^{5} = 32 \equiv 10$ and $2^{2} = 4$. Neither is 1.

Answer: Yes.

Worked example: Not a primitive root

Is $3$ a primitive root mod $13$?
  1. $p - 1 = 12 = 2^{2} \cdot 3$, so check $3^{6}$ and $3^{4}$.
  2. $3^{3} = 27 \equiv 1$, so $3^{6} \equiv 1$. That settles it: the order of 3 is only 3.

Answer: No.

Worked example: The smallest one

Find the smallest primitive root mod $23$.
  1. $22 = 2 \cdot 11$, so check $g^{11}$ and $g^{2}$.
  2. $g = 2$: $2^{11} = 2048 = 89 \cdot 23 + 1$, so no. $g = 3$: $3^{11} \equiv 1$ too, so no. $g = 4 = 2^{2}$: $4^{11} = (2^{11})^{2} \equiv 1$, no.
  3. $g = 5$: $5^{2} = 25 \equiv 2$ and $5^{11} \equiv 22 \equiv -1$. Neither is 1, so 5 is a primitive root.

Answer: $5$.

Common mistake

"Testing" with $g^{p-1} \equiv 1$. By Fermat's theorem every nonzero $g$ passes that, primitive root or not: $3^{12} \equiv 1 \pmod{13}$ even though $3$ has order 3. The test must show that the smaller powers $g^{(p-1)/q}$ are not 1.

Key idea

$g$ is a primitive root mod $p$ when its powers reach every nonzero residue, that is, when $\operatorname{ord}_p(g) = p - 1$. Test it by checking $g^{(p-1)/q} \not\equiv 1$ for each prime $q \mid p - 1$.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 3 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • William Stein, Elementary Number Theory: Primes, Congruences, and Secrets (Springer, 2009; free online edition), chapter 2, The Ring of Integers Modulo n (the structure of (Z/pZ)*)
  • MIT OpenCourseWare 18.781 Theory of Numbers (Spring 2012), lecture notes on primitive roots
@teddyrookbook GitHub