Primitive Root Calculator

Test whether g is a primitive root modulo n by checking generated residues. This educational calculator shows the formula, result, and step-by-step interpretation.

Discrete MathCryptography

Calculator

What this calculator teaches

Primitive roots are important in Diffie-Hellman, discrete logarithms, and cyclic groups.

Use the result as a learning aid. For classwork, still show the formula and intermediate reasoning so the final answer is not just a black-box number.

Primitive Roots and Multiplicative Order

For a modulus n, the invertible residue classes form the multiplicative group of units modulo n. A number g is a primitive root modulo n when the powers g¹,g²,… generate every unit before returning to 1. Equivalently, the multiplicative order of g equals Euler’s totient φ(n).

The calculator repeatedly multiplies by g modulo n and records the residues until 1 reappears. If the number of distinct generated units equals the total number of units, g is primitive. The condition gcd(g,n)=1 is necessary because only units can belong to the multiplicative group.

ConceptRule
Unitgcd(a,n)=1
Order of gsmallest k>0 with gᵏ≡1 mod n
Primitive rootordₙ(g)=φ(n)

Not every modulus has primitive roots. A classical theorem says primitive roots exist exactly for n=1,2,4,pᵏ, and 2pᵏ where p is an odd prime. For many classroom examples, a prime modulus is used; then every nonzero residue is a unit and a primitive root has order p−1.

A quick prime-modulus test can use factors of p−1. For prime p, g is primitive exactly when g^((p−1)/q) is not congruent to 1 modulo p for every prime factor q of p−1. This factor test is often faster than listing every power when p is large, although enumerating residues is excellent for learning.

When checking a power sequence by hand, reduce after every multiplication. For example, modulo 7 the sequence for g=3 is 3, 9≡2, 6, 18≡4, 12≡5, 15≡1. Keeping residues small prevents arithmetic growth and makes it obvious when the cycle returns to 1.

Formula & Symbols

ConceptFormula or rule
Primitive rootpowers of g generate all units modulo n
Ordersmallest k with gᵏ ≡ 1 mod n

Worked example

Example: 2 is a primitive root modulo 11 because its powers generate all nonzero residues.
Example 2: Modulo 7, powers of 3 are 3,2,6,4,5,1, so 3 has order 6=φ(7) and is primitive.
Example 3: Modulo 7, powers of 2 are 2,4,1, so order 3<6; therefore 2 is not primitive.
Example 4: Modulo 11, 2 has order 10 and generates all nonzero residues, so it is a primitive root.
Example 5: Modulo 8, the unit group is {1,3,5,7}; every nonidentity unit squares to 1, so no element has order 4 and there is no primitive root.

Common mistakes

⚠️
Using the wrong input format

Keep lists comma separated, matrices as rows separated by semicolons, and modular inputs as integers.

⚠️
Ignoring assumptions

Some methods require positive probabilities, valid moduli, independent trials, or small educational input sizes.

⚠️
Testing a value that is not coprime to n

If gcd(g,n)≠1, g is not even a unit, so it cannot be a primitive root.

⚠️
Comparing the order with n−1 for composite n

The relevant group size is φ(n), not automatically n−1. They are equal only when n is prime.

FAQ

Can I use decimals?
Most numerical calculators allow decimals, but modular arithmetic and coding-theory tools usually require integers or binary strings.
Is this for homework checking?
Yes. The page is designed to show both the answer and the reasoning pattern.
Why does the result sometimes say approximate?
Some probability, floating-point, and numerical methods naturally produce approximations.
What is multiplicative order?
It is the smallest positive exponent k for which gᵏ≡1 modulo n.
Are primitive roots unique?
No. When primitive roots exist, there can be several generators of the same unit group.
Does every prime have a primitive root?
Yes. The multiplicative group modulo any prime p has primitive roots.
Why are primitive roots useful?
They organize cyclic modular groups and appear in number theory and classical constructions used in cryptography.

Related calculators

These links will work after the calculators are registered in the final Math layout update.

Formula Explorer connections

Interpretation: This formula uses integer divisibility, modular arithmetic, finite fields or coding relationships. Assumption: Inputs are usually integers with specific modulus or coprimality requirements. Cryptographic examples are educational and not a substitute for vetted security libraries.

RSA Mathematics Calculator →Vigenere Index of Coincidence Calculator →Affine Cipher Math Calculator →Math Formula Explorer →