Primitive Root Hot Sheet¶
Use this page when the task is:
given prime p, output one primitive root modulo p
and you want the shortest safe route back to the generator test.
Do Not Use When¶
- the unknown is in the exponent rather than the base
- the exact task is only
x^2 ≡ a (mod p) - the modulus is composite and you have not separated that case
- factoring
p - 1is the real bottleneck and this starter contract is too narrow
Choose By Signal¶
- find one generator modulo one prime ->
primitive-root-prime.cpp - recover
xfroma^x ≡ b (mod m)-> Discrete Log hot sheet - recover one square root from
x^2 ≡ a (mod p)-> Modular Square Root hot sheet - merge residue classes or solve
a x ≡ b (mod m)-> Chinese Remainder / Linear Congruences - only need powers / inverses / binomials -> Modular Arithmetic hot sheet
Core Invariants¶
- for prime
p, the nonzero residues form a cyclic group of sizep - 1 - candidate
gis primitive iff:
\[
g^{(p-1)/q} \not\equiv 1 \pmod p
\]
for every distinct prime divisor q of p - 1
p = 2is the trivial edge case with answer1- the first route is only as good as your access to the distinct prime divisors of
p - 1
Main Traps¶
- forgetting to deduplicate prime divisors of
p - 1 - testing the prime-mod criterion unchanged under composite moduli
- forgetting the
p = 2edge case - using trial division when the true bottleneck is 64-bit factorization of
p - 1
Exact Starters In This Repo¶
- exact starter ->
primitive-root-prime.cpp - flagship in-lane rep -> Primitive Root
- compare points -> BSGS / Discrete Log, Modular Square Root / Discrete Root
- nearby foundation -> Modular Arithmetic hot sheet
Reopen Paths¶
- full lesson -> Primitive Root
- broader chooser -> Number Theory cheatsheet
- template chooser -> Template Library