How this calculation works
A primitive root modulo a prime generates every nonzero residue by repeated multiplication. The important quantity is its multiplicative order: the first positive exponent that returns a remainder of one. For a generator this order is p minus one, the size of the nonzero group. The calculator searches candidates in increasing order and reports the smallest passing candidate, together with a short certificate that rules out every possible smaller order.
g is primitive modulo p iff g^((p−1)/q) ≠ 1 (mod p) for every prime divisor q of p−1.A worked example
Modulo 7, powers of 3 beginning at exponent zero give 1, 3, 2, 6, 4 and 5, then return to 1. Since 6 = 2 × 3, test exponents 6/2 = 3 and 6/3 = 2. The remainders are 6 and 2, both different from 1. Candidate 2 fails because 2³ ≡ 1, making 3 the smallest generator.
Good to know
The modulus must be prime and at most ten million. This page searches for one smallest generator, rather than listing every generator or supporting every composite modulus that has primitive roots. All certificate arithmetic is exact. Large cryptographic parameters are outside its browser workload.
Reference: SymPy — modular arithmetic reference (opens in a new tab) ↗
A generator visits the whole nonzero group
For p = 7, the nonzero residues are 1 through 6. The default generator 3 visits each of them exactly once before its powers repeat. By contrast, powers of 2 cycle through only 1, 2 and 4. Merely being nonzero or coprime to the modulus does not make a number a generator; those conditions only place it inside the multiplicative group.
The identity residue 1 is included at exponent zero. The first positive return to 1 happens at exponent six for 3, so its order is six rather than seven. Modulus 2 is the small exceptional-looking case: its nonzero group has only the element 1, which is also the generator and has order one.
Use prime-divisor tests instead of printing every power
An element’s order must divide p − 1. If that order is a proper divisor, at least one prime q dividing p − 1 can be removed while leaving an exponent divisible by the order. Thus one of the tests g^((p−1)/q) would return 1. Passing all such tests rules out every proper divisor at once. Only the distinct prime factors are needed; repeated copies of the same prime do not create extra tests.
The certificate table shows the actual exponent and remainder for each q. This is more compact than listing as many as millions of powers, while still exposing a direct verification. The existing multiplicative order calculator answers a related question for a supplied candidate. This page instead searches for a candidate with the largest possible order. Composite moduli are rejected because their group structure requires different existence conditions.
A few questions, answered
Is the smallest primitive root always prime?
The search is over residue representatives; primality of the representative is not the defining condition. The certificate tests multiplicative order, not whether the candidate itself is a prime.
Can a prime have several primitive roots?
Yes. This calculator returns the smallest one. Other generators are powers of that generator with exponents coprime to p − 1.