Euler Totient Calculator
Count how many whole numbers up to n share no factor with n, with the prime factorization shown.
What it does
Euler's totient answers a counting question: among the numbers 1 through n, how many have no common factor with n other than 1? Those numbers are called coprime to n, and the count is written phi(n). The answer turns up whenever you need to know how many residues form a group under multiplication modulo n.
The function is named after Leonhard Euler, who studied it in the eighteenth century. It sits at the center of Euler's theorem, which says that a raised to phi(n) is congruent to 1 modulo n whenever a and n are coprime. That result is the basis of RSA encryption, so a counting idea from pure number theory ends up securing web traffic.
Computing phi(n) by testing every number up to n works for tiny inputs but becomes slow quickly. The product formula is far faster. It says to take n, then for each distinct prime p that divides n, multiply by (1 - 1/p). Repeats of the same prime are counted only once, which is why 12 and 6 both contribute the primes 2 and 3.
This page factors n, applies that product, and reports the count together with the factorization so you can check the work. It also accepts large integers up to one trillion, which is well beyond the range where hand counting would be practical.
The result is a pure count with no unit. It says nothing about how large the coprime numbers are, only how many of them exist in one full block. For the related question of how many divisors n has, use a divisor count tool instead.
How to use
- Enter a whole number n of at least 2 in the input box.
- Read the main result, which is phi(n).
- Check the distinct prime factor count beside it.
- Read the prime factorization to see which primes entered the product.
- Try n = 12 first, since the page opens on that worked example.
- Change n to a prime such as 97 to confirm the count drops by exactly one.
Formula
- n
- The positive integer being counted, from 2 upward.
- p
- A distinct prime divisor of n, counted once no matter its exponent.
- phi(n)
- The number of integers from 1 to n that are coprime to n.
The product runs over distinct primes only. For n = 12 the primes are 2 and 3, so phi(12) = 12 x (1/2) x (2/3) = 4. For a prime p there is just one factor, giving phi(p) = p - 1. The value phi(1) is defined as 1, but this tool starts at 2 to keep the worked steps visible. Each intermediate division is exact, so large inputs stay free of rounding error.
Worked example
Example: phi(12)
Take n = 12, the default value on this page.
- Factor 12 into 2^2 x 3.
- List the distinct primes: 2 and 3, so the count is 2.
- Multiply 12 by (1 - 1/2), which gives 6.
- Multiply 6 by (1 - 1/3), which gives 4.
- The tool reports phi(12) = 4, two distinct primes, and factorization 2^2 x 3.
- Check by listing: only 1, 5, 7 and 11 are coprime to 12, four numbers.
Reference table
| n | Prime factorization | phi(n) |
|---|---|---|
| 6 | 2 x 3 | 2 |
| 10 | 2 x 5 | 4 |
| 12 | 2^2 x 3 | 4 |
| 15 | 3 x 5 | 8 |
| 30 | 2 x 3 x 5 | 8 |
| 36 | 2^2 x 3^2 | 12 |
Limits
- The count covers 1 through n only, not a larger range.
- Inputs above one trillion are rejected so factoring stays fast in the browser.
- The tool does not compute the inverse problem of finding every n with a given totient.
- It gives a cardinality, not the list of coprime integers themselves.
Common mistakes
- Repeating a prime that appears more than once in the factorization, which shrinks the answer too far.
- Using n - 1 for a composite n, which is only correct when n is prime.
- Counting from 0 instead of 1 and assuming the endpoint changes the total.
- Confusing phi(n) with the number of divisors of n.
- Rounding the intermediate fractions instead of dividing exactly.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is phi(36)?
36 = 2^2 x 3^2, so phi(36) = 36 x (1/2) x (2/3) = 12.
What is phi(97)?
97 is prime, so phi(97) = 97 - 1 = 96.
What is phi(30)?
30 = 2 x 3 x 5, so phi(30) = 30 x (1/2) x (2/3) x (4/5) = 8.
Questions
What does coprime mean?
Two numbers are coprime when their greatest common factor is 1.
Why does the prime exponent not matter?
The factor (1 - 1/p) is applied once per distinct prime, so 2^2 and 2 contribute the same factor.
Is phi(n) always even?
For every n greater than 2 it is even. The exceptions are n = 1 and n = 2, which both give 1.
Where is the totient used?
In Euler's theorem and in the key setup of RSA, where the size of the unit group matters.
Can two numbers share a totient?
Yes. For example phi(12) and phi(10) are both 4, so the function is not one to one.
How large an input does this page accept?
Any whole number from 2 through 1,000,000,000,000. Larger entries return a clear error.
Sources
- OEIS A000010, Euler totient function
- Wikipedia: Euler's totient function
- The Prime Glossary: Euler's phi function