Cototient calculator
The cototient of 36 is 24: that many numbers from 1 to 36 share a factor with 36. Enter any positive integer up to one trillion and get the exact count, n minus Euler's totient. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 36
- Cototient
- 24
The cototient of a positive integer n is n minus Euler's totient phi(n). It counts the integers from 1 through n that are not coprime to n, including n itself. This calculator returns the exact value from deterministic prime-factor arithmetic, without random sampling, floating-point approximation, or an external service. Enter one positive integer to check a number-theory exercise, explore how shared factors change the count, or add a dependable cototient step to an automated workflow.
What the cototient measures
Euler's totient phi(n) counts the positive integers no greater than n that are coprime to n, meaning their greatest common divisor with n is one. The cototient takes the complementary count: n minus phi(n). Consequently, it counts values in the same range that share a factor with n.
For a prime p, every smaller positive integer is coprime to p, so phi(p) is p minus one and the cototient is one. Composite numbers usually have larger cototients because multiples of their prime factors overlap the range. For example, n equal to 12 has phi(12) equal to four, so its cototient is eight.
This interpretation makes the result useful when a problem asks for non-coprime residues, excluded reduced fractions, or the complement of a familiar totient count. The calculator returns a compact object containing the normalized input and its cototient, which keeps the primary result clear for both people and programs.
How the exact calculation works
The implementation first validates that n is an integer from one through the published upper bound. It then factors n by deterministic trial division, removing the factor two before testing odd divisors. Each distinct prime factor p updates the running totient with the integer form of Euler's product formula: divide the current value by p and multiply by p minus one.
Repeated powers of the same prime are removed before continuing, because each distinct prime appears only once in the product. If a prime cofactor remains after trial division, the algorithm applies one final update. The cototient is then obtained by subtracting this exact phi value from n.
All accepted values are within JavaScript's safe-integer range, and every arithmetic step remains integral, so the result does not depend on rounding. There is no network request, random choice, current time, or mutable cache.
When this calculator is the right tool
Use the browser calculator for individual values when studying elementary number theory, checking a complement to phi(n), or comparing prime and composite inputs. The accepted ceiling of one trillion keeps trial division bounded and makes the runtime practical for this simple analytic engine; this capability is not intended to factor cryptographic-size integers or replace specialized large-integer software. Remember that cototient is defined here precisely as n minus Euler's totient, not as a list of the non-coprime values and not as a probability.
If you need the members themselves, their greatest common divisors, or a factorization report, use a tool designed for that richer output. For stable integrations, consume the cototient field directly and treat validation messages as diagnostic text rather than building control flow around their exact wording.
What you can do with it
Check number-theory exercises
Confirm the complement of Euler's totient for a positive integer without manually listing every non-coprime value.
Generate teaching materials
Produce deterministic cototient answers for worksheets that compare primes, prime powers, and composite numbers.
Validate integer pipelines
Add an exact cototient calculation to tests or preprocessing jobs that already work with bounded positive integers.
FAQ
What is the cototient of n?
It is n minus Euler's totient phi(n), equivalently the count of integers from 1 through n that are not coprime to n.
What is the cototient of one?
It is zero because phi(1) is one, so 1 minus phi(1) equals zero.
How is the result calculated?
The solver finds the distinct prime factors of n, computes phi(n) with Euler's product formula using exact integer steps, and subtracts phi(n) from n.
What is the cototient of 12?
It is 8. Euler's totient of 12 is 4, so 12 − 4 = 8 numbers between 1 and 12 share a factor with 12, and 12 itself is one of them.
What is the cototient of a prime number?
It is always 1. Every smaller positive number is coprime to a prime, so the only number in the range that shares a factor with it is the prime itself.
Related tools
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/cototient \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":36}'const res = await fetch("https://api.kit.forhosting.com/numth/cototient", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 36
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/cototient",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 36
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/cototient", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":36}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":36}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/cototient", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 36
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.cototient",
"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_n | 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. |
Technical notes
What the cototient measures
The endpoint includes n itself in that complement because gcd(n, n) equals n rather than one, except that the definition still gives cototient zero for n equal to one.
How the exact calculation works
Invalid values, including zero, negative numbers, fractions, missing n, and numbers above the bound, produce an invalid_input error instead of a misleading numerical answer.
Using the calculator and API responsibly
Use the API when a script, worksheet generator, test suite, or educational service needs the same deterministic operation repeatedly. Send n as a JSON integer; an integer-form string is also normalized by the shared solver for browser compatibility. A successful request is priced at $0.002 per item, while input rejected during validation does not produce a computed result.
Technical questions
What happens when n is below one?
The request fails with invalid_input. The capability accepts positive integers only.
How much does an API request cost?
Each successful request costs $0.002 per item. The browser calculator can run the same deterministic logic locally.