Euler's Totient Calculator

What this calculator finds

Euler's totient function, written φ(n), answers a very specific counting question: among the positive integers below n, how many are coprime to n? Two numbers are coprime when their greatest common divisor is 1, which means they share no prime factor. That sounds abstract at first, but it shows up all over number theory. Totients describe how many residues are invertible modulo n, they help explain the behavior of modular arithmetic cycles, and they appear in topics ranging from fraction reduction to RSA-style cryptography. This calculator turns that idea into a fast one-input computation. You enter a positive integer n, and the page returns the exact value of φ(n).

The result is always a whole number. It is not a percentage, a probability, or a physical unit. It is literally a count of integers. If you enter 12 and get 4, that means there are four positive integers less than 12 that share no factor with 12 other than 1. Those integers are 1, 5, 7, and 11. If you enter a prime number such as 13, the answer is 12 because every positive integer from 1 through 12 is coprime to 13. At the opposite extreme, when a number has several small prime factors, its totient is usually much smaller because many candidates get ruled out.

What the input means

This calculator has one input for a reason: the totient function depends on one integer n. Enter any positive whole number at least 1. Decimals do not make sense here because φ(n) is defined for integers. Negative values and zero are also outside the intended domain. The number you enter is unitless. It does not represent dollars, seconds, meters, or rates. It is just an integer whose divisibility structure determines the output.

The smallest interesting edge case is n = 1. The calculator returns 1, matching the standard convention in number theory. For every value greater than 1, you can interpret the answer as the count of positive integers strictly less than n that are relatively prime to n. If you are learning the topic, it helps to imagine a list from 1 up to n − 1 and cross out every number that shares any common prime factor with n. Whatever remains is the totient.

What “coprime” really means

The crucial test behind φ(n) is the greatest common divisor. A number a contributes to the count if and only if gcd(a, n) = 1. That condition is often easier to think about through factors. If n = 10, then any number divisible by 2 or 5 is not coprime to 10, because 10 itself is built from the prime factors 2 and 5. So among the integers below 10, the valid ones are 1, 3, 7, and 9. This is why the answer is φ(10) = 4. The calculator performs this logic efficiently, but the idea underneath is still a clean filter: shared factor means reject, no shared factor means count it.

That viewpoint also explains why prime factorization matters more than raw size. The number 29 is larger than 28, but φ(29) is 28 because 29 is prime, while φ(28) is only 12 because 28 has repeated shared factors through 2 and 7. In other words, the answer depends less on “how big” n is and more on “which primes divide it.”

How the totient formula works

The direct definition of φ(n) is a count, but the efficient formula uses prime factors. If the distinct prime divisors of n are p1, p2, …, pk, then the totient is

φ ( n ) = n · p | n ( 1 - 1 p )

That product runs over the distinct primes dividing n. Distinct is the key word. If a prime factor repeats, it still appears only once in the product. For example, 12 factors as 22 × 3, but the formula uses only 2 and 3 once each: φ(12) = 12(1 − 1/2)(1 − 1/3) = 4. Repeated powers matter when you factor the number, but they do not create new exclusion rules. A number that shares factor 2 with 12 is already eliminated; having another factor 2 in 12 does not eliminate it twice.

When the factorization is written explicitly as

n = p1a1 pkak

the same totient formula becomes

φ ( n ) = n (1-1p1) (1-1pk)

In words, start with n, then reduce it by the fraction excluded by each distinct prime factor. Every prime p removes the share of integers that are multiples of p. The calculator's script follows a factor-based method: it searches for prime divisors, strips each one out completely, and updates the running value of φ(n). That is why it stays fast even for fairly large inputs.

At the broadest level, any calculator is still a function of its inputs. The two general MathML blocks below were already part of the page, and they still apply in the abstract sense: the totient tool takes one input and returns a computed output. In this specific calculator, the algorithm is specialized to coprime counting rather than weighted totals, but the general function viewpoint is still useful context.

R = f ( x1 , x2 , , xn ) T = i=1 n wi · xi

Worked example: finding φ(12)

Suppose you enter n = 12. The positive integers below 12 are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11. Now ask which of these share a factor with 12. Since 12 = 22 × 3, any multiple of 2 or 3 must be rejected. That eliminates 2, 3, 4, 6, 8, 9, and 10. The survivors are 1, 5, 7, and 11, so the count is 4. Therefore, φ(12) = 4.

The factor formula gives the same answer more quickly:

φ(12) = 12(1 − 1/2)(1 − 1/3) = 12 × 1/2 × 2/3 = 4.

This is a good example of why the formula is efficient. You do not have to test every number one by one if you already know the prime factors. The primes 2 and 3 describe exactly which values fail the coprime test. Everything else is bookkeeping.

Second example: finding φ(36)

Now try n = 36. A common first instinct is to think the answer should be close to 36 because the number is large, but factorization matters more than size. Since 36 = 22 × 32, the distinct prime factors are still just 2 and 3. Any number below 36 that is divisible by 2 or by 3 is excluded. The formula gives

φ(36) = 36(1 − 1/2)(1 − 1/3) = 36 × 1/2 × 2/3 = 12.

So only 12 integers below 36 are coprime to 36. That result is much smaller than 36 because the filters “multiple of 2” and “multiple of 3” remove a large share of the candidates. This example is a helpful reminder that repeated powers do not add new distinct filters, but the presence of small prime factors can shrink the totient dramatically.

Quick comparison examples

The pattern becomes easier to see when you compare several values side by side.

n Prime factorization φ(n) Why the result looks that way
8 23 4 Only the multiples of 2 are excluded, so exactly half of the numbers below 8 survive.
10 2 × 5 4 Multiples of 2 and 5 are removed, leaving 1, 3, 7, and 9.
13 prime 12 Every positive integer below a prime is coprime to it.
18 2 × 32 6 The distinct filters are still 2 and 3, so many candidates are eliminated.
30 2 × 3 × 5 8 Three small prime factors exclude most numbers below 30.

Notice that 13 has a much larger totient than 18 even though the numbers are close. Again, the structure of the prime factors matters more than raw magnitude.

How to interpret the result

When this page displays something like phi(30) = 8, the most useful interpretation is practical: there are eight invertible residue classes modulo 30 among the positive integers below 30. If you are studying modular arithmetic, those are the values that have multiplicative inverses mod 30. If you are learning Euler's theorem, the result also tells you the exponent that appears in statements like aφ(n) ≡ 1 mod n whenever gcd(a, n) = 1. If you are working with reduced fractions, the totient can be read as the number of numerators between 1 and n − 1 that would already be in lowest terms over denominator n.

You can also use the result for intuition. Prime numbers have the largest possible totient relative to their size because nothing below them shares a factor with them. Numbers built from several small primes have much smaller totients because many candidates fail the gcd test. So if you compare two nearby inputs and see a surprisingly big jump or drop, do not think of that as instability in the calculator. It is usually real arithmetic caused by a change in factorization.

One more interpretation detail matters: φ(n) counts valid integers, not the integers themselves. The calculator does not list every coprime value in the result box. It gives the count. If you need the actual list, you can generate it manually for small values by checking gcd(k, n) = 1 for each k from 1 to n − 1, or you can use the mini-game below to build that instinct visually.

Assumptions, limitations, and sanity checks

This calculator is exact for positive integer inputs, but it still has boundaries. It is not designed for symbolic algebra, fractions, decimals, or negative values. Very large integers can also be slower in any browser-based tool because the factor search must still examine potential divisors, even though the method is efficient for ordinary use. The result should always be an integer between 1 and n − 1 for n greater than 1. If you ever see a non-integer in your own hand work, that means an arithmetic mistake slipped into the factorization or product step.

A good way to sanity-check your answer is to ask whether the factor structure matches your expectation. For a prime input, the result should be one less than the input. For a power of two, exactly half of the numbers below it are odd, so φ(2k) = 2k−1. For a number with several distinct small primes, the answer should be noticeably smaller than the input. Those quick checks catch many mistakes before they matter.

  • Check integrality: φ(n) must be a whole number.
  • Check prime inputs: if n is prime, the answer must be n − 1.
  • Check factor logic: adding distinct prime factors usually lowers the surviving share.

Used that way, the calculator is more than a black box. It becomes a fast confirmation tool for the number-theory logic you already understand.

Enter a whole number n at least 1. The result is the number of positive integers less than n that are relatively prime to n. For the special case n = 1, the standard convention gives φ(1) = 1.

Enter a positive integer.

Mini-game: Coprime Orbit

Want the definition to feel more intuitive instead of purely symbolic? Coprime Orbit turns the same idea behind φ(n) into a fast visual challenge. Each wave places a target value n in the center of the canvas and arranges the numbers below it around an orbit. Your job is to click only the numbers that are coprime to n. The HUD shows the target count, your streak, and the remaining time, while later waves speed up, reverse direction, or switch to prime-heavy rounds. The game is optional and separate from the calculator itself, but it is designed to make the coprime filter behind the totient function feel immediate.

Score0
Time75.0s
Streak0
Wave0
Targetn=—
Progress0/0

Coprime Orbit

Click the numbers around the orbit that are coprime to the center value n. Clear each orbit before the timer ends. Wrong picks cost 3 seconds and reset your streak.

  • Tap or click the orbiting numbers you think belong in φ(n).
  • Use the arrow keys and Space or Enter if you prefer a keyboard.
  • Every few waves the orbit speeds up, reverses, or shifts into a prime rush.

Best score: 0

Tip: when n has several small prime factors, fewer orbiting numbers survive the coprime test, which means φ(n) drops.

Embed this calculator

Copy and paste the HTML below to add the Euler's Totient Calculator | Find φ(n) and Count Coprime Integers to your website.