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.
Run — free
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.
What you can do with it
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.
FAQ
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.
For developers — API access
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.
API endpoint
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.
Call it from your stack
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}'const res = await fetch("https://api.kit.forhosting.com/numth/multiplicative-order", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": 2,
"n": 9
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/multiplicative-order",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": 2,
"n": 9
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/multiplicative-order", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":2,"n":9}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":2,"n":9}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/multiplicative-order", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"a": 2,
"n": 9
}Example response
{
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_abs | 1000000000000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |