ForHosting KIT · Developer Utilities

Multiplicative order calculator

The multiplicative order calculator finds the smallest positive exponent k for which a raised to k is congruent to 1 modulo n.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Enter an integer base a and a modulus n, and the result includes the reduced base, Euler’s totient, the order, and a direct modular check. The calculation is defined only when a and n are coprime, so invalid pairs produce a clear error instead of a misleading number. It is useful for modular arithmetic exercises, cyclic subgroup analysis, recurring patterns, and elementary number theory.

What multiplicative order means

For integers a and n, the multiplicative order of a modulo n is the least positive integer k such that a<sup>k</sup> leaves remainder 1 when divided by n. The phrase “least positive” matters: many later exponents may also produce 1, but the order is the first return to the identity in modular multiplication. For example, powers of 2 modulo 9 have residues 2, 4, 8, 7, 5, and then 1, so the order is 6. The concept describes the size of the cyclic subgroup generated by a among the invertible residue classes modulo n. This calculator reduces a to its standard nonnegative residue before doing any work, which means negative bases and bases larger than n are handled consistently. It also returns a check value computed from the reported order. A check of 1 confirms the defining congruence, while the reduction process ensures no proper divisor left in the candidate exponent can satisfy it.

Why coprimality is required

A multiplicative order modulo n exists only when gcd(a, n) is 1. This is not merely an input convention. An element must have a multiplicative inverse modulo n before its powers can belong to the finite group of units and return to 1. If a and n share a factor, every positive power of a retains a compatible divisibility obstruction, so it cannot be congruent to 1 modulo n. The calculator tests this condition immediately and reports the actual greatest common divisor when the condition fails. The modulus must also be at least 2, because the usual order problem is posed in a nontrivial residue system. The base may be zero, negative, or positive within the published bound, but zero succeeds only in no allowed modulus because it is never coprime to n. When preparing input, use exact integers rather than decimals or scientific approximations. This preserves the discrete arithmetic on which gcd, factorization, and modular powers depend.

How the calculator finds the smallest exponent

The calculator does not test every exponent one after another. It first factors n sufficiently to compute Euler’s totient phi(n). Euler’s theorem guarantees that a raised to phi(n) is congruent to 1 whenever gcd(a, n) is 1, so the desired order must divide phi(n). The algorithm then factors phi(n) and repeatedly asks whether dividing the current candidate by one of its prime factors still produces a modular power equal to 1. Whenever it does, the smaller candidate replaces the old one. After no prime factor can be removed, the remaining candidate is the multiplicative order. Modular exponentiation uses repeated squaring, keeping intermediate values reduced modulo n, and integer arithmetic is exact throughout. This approach is substantially faster than walking through every positive exponent, especially when the order is large. Inputs are bounded at one trillion so trial factorization has a clear deterministic ceiling suitable for both the browser tool and automated API calls.

Check a number theory exercise

Confirm the least exponent, Euler totient, reduced residue, and final congruence without manually listing a long sequence of powers.

Study cyclic subgroups

Measure the subgroup generated by an invertible residue and compare its order with phi(n) when investigating primitive roots.

Analyze repeating modular patterns

Find the exact period of repeated multiplication modulo n for recurrence, divisibility, and elementary cryptography calculations.

What does the multiplicative order result represent?

It is the smallest positive integer k for which a^k is congruent to 1 modulo n.

Why do a and n have to be coprime?

Only residues with gcd(a, n) equal to 1 are invertible modulo n and can have a multiplicative order.

Can the base a be negative?

Yes. The calculator reduces a to its nonnegative residue modulo n before computing the order.

Is the order always equal to Euler’s totient phi(n)?

No. The order always divides phi(n) for valid input, but it equals phi(n) only when a generates the full group of units modulo n.

What does the API request cost?

Each API request costs $0.002. The same deterministic calculation is available free in the browser.

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/multiplicative-order

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/multiplicative-order \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":2,"n":9}'
{
  "a": 2,
  "n": 9
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.multiplicative_order",
  "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_abs1000000000000
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 →