ForHosting KIT · Developer Utilities

All primitive roots modulo n

This all primitive roots modulo n calculator returns the complete, sorted set of generators of the multiplicative group of units modulo an integer n.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

It first determines whether the modulus belongs to one of the families that can have primitive roots, then computes Euler's totient, finds a generator, and derives every other generator from it. The response includes the modulus, totient, number of roots, and full root list. Invalid values below two and moduli without primitive roots produce a clear error instead of an empty or misleading answer. The same deterministic arithmetic supports quick browser checks and reproducible API automation at $0.002 per successful request.

What the complete primitive-root list means

A primitive root modulo n is a residue whose repeated powers generate every invertible residue class modulo n. The important word here is every: a number may be coprime to n and still cycle through only a proper subgroup, so being a unit is necessary but not sufficient. This capability returns all positive representatives between 1 and n minus 1 that have multiplicative order exactly phi(n). For modulus 14, for example, the unit group has six elements and the complete generator set contains two residues. The response reports n, Euler's totient phi, the number of primitive roots, and a numerically sorted primitive_roots array. The count provides a useful consistency check: whenever primitive roots exist, their number is phi(phi(n)). Sorting is part of the stable output contract, not a mathematical claim about preference among generators. The special modulus 2 correctly has the single root 1. A modulus that has no generator for its entire unit group is rejected explicitly; an empty list would wrongly suggest that the calculation merely found nothing rather than that the group is noncyclic.

How existence and each generator are verified

Primitive roots do not exist for every modulus. The classification theorem says that the multiplicative group modulo n is cyclic exactly when n is 2, 4, an odd prime power, or twice an odd prime power. The calculator factors n and checks that structural condition before searching. For an admissible modulus it computes phi(n), factors that group order, and tests candidate units using modular exponentiation. A candidate g has full order phi(n) precisely when g raised to phi(n) divided by q is not congruent to 1 modulo n for every distinct prime divisor q of phi(n). Once one such g is known, every primitive root is a power g to the k where k is coprime to phi(n), and those are all the primitive roots. The implementation enumerates those exponents, computes their residues exactly with integer modular exponentiation, and sorts the result. This route avoids checking the entire power cycle separately for every possible residue. It uses no random witnesses, external tables, network requests, or current time, so identical input always produces byte-for-byte equivalent numerical content.

Using the result in mathematics and software

Complete generator lists are useful when a problem asks for more than the least primitive root. Students can compare the returned residues with hand-built power tables and see why the number of generators equals phi(phi(n)). Teachers can build answer keys that include every valid answer rather than accepting only one chosen generator. Software authors can generate fixtures for multiplicative-order routines, verify enumeration code, or select among several generators according to a separate application rule. The calculator also makes the failure cases instructive: trying modulus 8 or 15 demonstrates that many familiar composite moduli have unit groups that are not cyclic, even though they contain plenty of invertible residues. Input is limited to 10,000 because the requested response is exhaustive and may contain many roots; the bound keeps browser rendering, API payload size, and runtime predictable. Supply n as an integer, or use a plain decimal integer string through clients that preserve textual form. Successful API requests cost $0.002; interactive use can rely on the same pure solver, and validation failures clearly identify unsupported or malformed input.

Check a number theory exercise

Compare a hand calculation against the complete sorted set of generators modulo n.

Generate deterministic test fixtures

Build exact expected values for code that computes multiplicative orders or cyclic unit groups.

Teach cyclic and noncyclic unit groups

Contrast admissible moduli with values that cannot have a primitive root and explain the classification theorem.

What does an API request cost?

A successful API request costs $0.002. Invalid input returns an error rather than a root list.

Which moduli have primitive roots?

Exactly 2, 4, odd prime powers, and twice odd prime powers. Other moduli are rejected because their unit groups are not cyclic.

Why can a coprime residue fail to be a primitive root?

Coprimality only makes the residue a unit. A primitive root must additionally have the maximum possible multiplicative order phi(n).

How many primitive roots should the result contain?

When primitive roots exist, their number is phi(phi(n)). The response includes the computed count alongside the array.

Why is n limited to 10,000?

The output lists every generator, so response size grows with n. The bound keeps exhaustive computation and payloads predictable.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/all-primitive-roots

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/all-primitive-roots \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":14}'
{
  "n": 14
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.all_primitive_roots",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_n10000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →