ForHosting KIT · Math

Sum of totatives

The numbers up to 10 that share no factor with 10 are 1, 3, 7 and 9, and they add up to 20. Enter a positive whole number to get that sum, its totient and its prime factors. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
N
10
You get
Sum
20
Phi
4

The totatives of a positive integer n are the residues in the range one through n that share no common prime factor with n. Their count is Euler's totient φ(n); their sum is a closely related arithmetic invariant that appears in fraction enumerations, cyclotomic identities, and modular-group exercises. This calculator takes a single positive integer n, factors it deterministically, evaluates φ(n) from the prime product formula, and returns the exact sum of totatives — using the classical closed form n times φ(n) over two when n is greater than one, and the special value one when n equals one. No network call, no floating-point guesswork, and no language model sit between your input and the integer answer.

What the sum of totatives measures

Two positive integers are coprime when their greatest common divisor is one. The set of totatives of n is exactly the set of integers k with one less than or equal to k less than or equal to n and gcd(k, n) equal to one. Euler's totient φ(n) counts that set; the sum of totatives adds its members.

For a prime p the totatives are one through p minus one, so the sum is (p minus one) times p over two, which matches p times φ(p) over two. For a composite n the same pairing idea applies whenever n is greater than one: if k is coprime to n then so is n minus k, the two are distinct, and they average to n over two, therefore the full sum equals n times φ(n) over two.

Students meet the sum when they check textbook tables of totatives, when they verify that the reduced fractions with denominator n have numerators that average to n over two, and when they compare φ(n) against a hand-built list of coprimes. Engineers meet it in number-theory pipelines that need both the count and the sum as cheap invariants of a modulus.

Having a single deterministic capability that returns n, the sum, φ(n), and the factors that produced φ(n) removes a common source of off-by-one mistakes in homework checkers and integer test harnesses.

How this calculator evaluates the sum

Call the capability with a positive integer field n. The implementation first validates that n is an integer in the published range from one through one trillion. It then factors n by trial division: peel off factors of two, then odd candidates up to the square root, and finally any remaining prime cofactor.

From that ordered factor list it applies the exact integer form of Euler's product: start with phi equal to n, and for every distinct prime p that divides n replace phi with floor of phi divided by p, times p minus one. When n equals one the sum is defined as one, because the only totative is one and the half-formula would incorrectly yield a half.

When n is greater than one the sum is n multiplied by phi and then divided by two; for every integer n greater than one the product n times φ(n) is even, so the result is always an exact integer with no remainder. The response includes n, sum, phi, the factor list as prime and exponent pairs, and a short formula string that records which case applied.

Practical use, limits, pricing, and delivery

Use the browser tool when you want an immediate sum of totatives while studying, grading a number-theory exercise, or cross-checking a hand enumeration of coprimes. The accepted range is integers from one through one trillion, which keeps every intermediate product inside JavaScript safe-integer territory while still covering typical contest, classroom, and application sizes. Results are fully deterministic: the same n always yields the same sum, the same phi, and the same factor list.

There is no language model, no external factoring service, and no randomness, so the capability is safe to pin in automated tests.

Homework and contest verification

Students and graders can confirm the sum of totatives for arbitrary positive integers, inspect φ(n) and the prime factors behind the formula, and catch off-by-one errors in hand-built lists of coprimes.

Fraction and modular-arithmetic tutorials

Teaching materials that introduce reduced fractions with fixed denominator n, or the structure of the multiplicative group modulo n, can show both φ(n) and the sum of totatives side by side.

What happens if n is less than 1?

The sum of totatives is defined for positive integers only; zero and negatives are rejected and not charged.

What formula is used for n greater than 1?

For n > 1 the sum equals n · φ(n) / 2.

Is the sum of totatives calculator free?

The browser tool runs free on your device.

What is the largest n I can submit?

Integers from 1 through 1,000,000,000,000 (1e12) are accepted. Larger values are rejected so arithmetic stays within safe integer range.

What are the totatives of 10 and their sum?

They are 1, 3, 7 and 9, the numbers up to 10 with no common factor with 10. There are four of them, so the totient is 4, and their sum is 20.

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/sum-of-totatives

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/sum-of-totatives \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":10}'
{
  "n": 10
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.sum_of_totatives",
  "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.

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.

What the sum of totatives measures

That identity is the reason this endpoint can return an exact integer without enumerating residues up to n.

How this calculator evaluates the sum

Inputs below one, non-integers, missing n, and values above the upper bound are rejected as invalid_input and are never charged.

Practical use, limits, pricing, and delivery

Use the API when a script, continuous-integration job, or educational platform needs the sum for many values without shipping a factorization library. Each successful request is one billable item at $0.002; failed validation does not consume balance. Wire the endpoint into fraction demos, modular-arithmetic tutorials, or integer preprocessing steps where you already trust exact arithmetic more than approximate heuristics, and keep the sibling Euler-totient capability for callers that only need the count of coprimes rather than their sum.

Automated number-theory pipelines

Scripts that enumerate reduced fractions, check textbook tables, or build integer invariants of a modulus can call a single deterministic item-priced endpoint instead of embedding factorization and pairing logic.

How do I compute the sum of the totatives of n?

Send a JSON body with positive integer field n to the numth.sum_of_totatives capability. The response returns sum, phi, the ordered prime factorization, and a formula string for the case that applied.

Read the full KIT documentation →