The guide
Counting the numbers that share nothing with n tells you how a clock of n hours behaves
Euler's totient counts the whole numbers up to n that have no prime in common with n. That one count decides which steps on a modular clock reach every hour.
- phi(36) = 12 numbers up to 36 that share no factor with 36
- 14 the smallest even number that is never a totient
- 80 lambda(561), against phi(561) = 320
- 2^64 limit below which twelve fixed bases settle primality
- 61% chance that two random whole numbers are coprime
Read the full guide Fold the guide
Take a clock with 36 marks round its face and a hand that jumps a fixed number of marks each tick. Jump by 5 and the hand visits every mark before it comes home. Jump by 6 and it visits only six of them, again and again. The difference is not luck. It depends on whether the step shares a prime factor with 36.
The count that sorts the steps
Two whole numbers are coprime when the only positive number dividing both is 1. That is the same as saying their greatest common divisor is 1. Euler’s totient, written with the Greek letter phi, counts how many numbers from 1 up to n are coprime to n.
For 36 the answer is 12. The numbers are 1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31 and 35. Every one of them is odd and none is a multiple of 3. So phi(36) = 12, and those twelve are exactly the steps that carry the hand round the whole clock.
Euler introduced the function in 1763 without a symbol for it. The letter phi comes from Gauss’s treatise of 1801, and the word totient was coined by Sylvester in 1879. Counting is the whole definition, so the tool counts. A chatbot asked for phi of a big number tends to fail in the same few ways. It miscounts, it forgets that a repeated prime counts only once in the product, or it mixes phi up with the Carmichael function lambda. Each of those slips is checkable, and the page checks it by counting.
Why the product formula works
Start with all n numbers. Every prime p that divides n removes one number in every p, because every p-th number is a multiple of p. What survives is the fraction 1 minus 1/p. Do that for each distinct prime and you get the product formula: n times the product of (1 - 1/p) over the primes dividing n.
Run it on 36 = 2^2 x 3^2. Half of the 36 numbers are even, which leaves 18. A third of those 18 are multiples of 3, which leaves 12. In symbols, 36 x 1/2 x 2/3 = 12. The repeated primes never appear twice, because 2 and 3 are each either a factor or not.
There is an equivalent whole-number form. For a prime power, phi(p^e) = p^(e-1) x (p - 1), since only the multiples of p fail. Then phi is multiplicative: when two numbers are coprime, phi of the product is the product of the phis. Here phi(4) x phi(9) = 2 x 6 = 12, the same answer.
A prime p is the extreme case. Everything below it is coprime to it, so phi(p) = p - 1. The reverse is also true, which gives a clean test: n is prime exactly when phi(n) = n - 1. The page uses that statement, but it never accepts a prime on trust. It shows the proof it has.
How common is coprimality? Pick two whole numbers at random and the chance they are coprime is about 61%, a figure that comes from 6 divided by pi squared. The sum of phi(k) for k up to n grows like 3 n^2 / pi^2, so phi(k) / k averages about 61% too, though it dips well below that when k has many small primes.
Euler’s theorem and the sharper Carmichael value
The totient earns its keep in modular arithmetic. The numbers coprime to n form a group under multiplication modulo n, and the size of that group is phi(n). Euler’s theorem follows: if a is coprime to n, then a raised to the power phi(n) leaves remainder 1 when divided by n.
When n is a prime, this is Fermat’s little theorem. Euler proved that special case in 1736 and the general one in 1763. Take a = 2 and n = 7: phi(7) = 6, and 2^6 = 64 = 9 x 7 + 1. The remainder is 1, as promised.
The multiplicative order of a modulo n is the smallest exponent k of 1 or more with a^k leaving 1. By Lagrange’s theorem on groups, that order always divides phi(n). The order of 2 modulo 7 is 3, which does divide 6. A number whose order equals phi(n) is called a primitive root. The group is cyclic, and so has one, only when n is 1, 2, 4, an odd prime power or twice one; 36 has none.
So phi(n) is a safe exponent, but often not the smallest one. The Carmichael function, written lambda, is the smallest exponent that works for every coprime a at once. It is the exponent of the group, where phi(n) is its size. Always, lambda(n) divides phi(n).
The rules are short. For 1, 2, 4 and odd prime powers, lambda equals phi. For 2^e with e of 3 or more, lambda is half of phi, namely 2^(e-2). For a general n, take the least common multiple of lambda over its prime powers. For 360 = 2^3 x 3^2 x 5 that gives lcm(2, 6, 4) = 12, though phi(360) = 96.
A composite number that fools a test
Fermat’s little theorem suggests a primality test: raise a to the power n - 1 and look for 1. A prime always passes. Most composites fail. But 561 = 3 x 11 x 17 passes for every base coprime to it, because lambda(561) = 80 and 80 divides 560.
Such numbers are called Carmichael numbers, and 561 is the first. The first seven were found by the Czech mathematician Simerka in 1885, before Korselt or Carmichael wrote about them, and Korselt gave a criterion in 1899: a composite n is a Carmichael number exactly when it has no repeated prime and each p - 1 divides n - 1. Here 2, 10 and 16 all divide 560. Phi alone would misreport this. It says 320, and 320 does not divide 560, yet a^560 still equals 1. Only lambda explains why the test is fooled. That is why the tool shows both numbers and says which is the smallest returning exponent.
Running it backwards
The inverse question is to find every n with phi(n) = m. For m = 12 the answers are 13, 21, 26, 28, 36 and 42. The search needs only primes p for which p - 1 divides m, because any prime power in n contributes a factor p - 1 to the product.
Some values never appear. Every odd m above 1 is a nontotient, because phi(n) is even once n reaches 3. There are even gaps too, and 14 is the first one. No whole number has exactly fourteen coprime partners below it. The list of such even values runs 14, 26, 34, 38 and on without end.
Going the other way, a value can be hit more than once. Ford proved in 1999 that every multiplicity of 2 or more occurs. Whether any value is hit exactly once is the question behind Carmichael’s totient conjecture, which says none is; no such value is known.
Limits, and how the page keeps its promises
All of this needs the prime factors of n, and factoring is the expensive part. The tool tries small primes first, then Pollard’s rho method, whose running time grows with the square root of the smallest prime factor. Up to 18 digits it always finishes. Up to 40 digits it tries for ten seconds, and if it cannot finish it gives no phi rather than a guess.
Primality is settled with the Miller-Rabin test. With the first twelve primes, 2 through 37, as the only bases, the test is deterministic for every n below 2^64. Above that limit the page accepts a prime only when a Pocklington certificate exists, built from a full factorisation of n - 1.
JavaScript’s BigInt type keeps every digit exact, but it cannot be mixed with ordinary numbers, so the code converts deliberately. The heavy searches run in a Web Worker, a separate thread, so typing stays smooth and a cancel button can stop a long job.
To reproduce the worked example, enter 36 and read phi = 12 with its formula 36 x 1/2 x 2/3. Then enter 561 with a = 2 and compare lambda = 80 against phi = 320. Last, enter 14 in the inverse panel and read the plain statement that there is no solution.
What this does not do is break codes. The totient appears in the toy ciphers taught alongside it because it is the size of the group, but turning that into a real attack means factoring n, and the page stops at its stated limit. It computes the function, shows the working and checks the answer by counting.
Sources
Every source consulted for this guide. Links checked November 10, 2026.
- Euler's totient function Wikipedia (CC BY-SA)
- Carmichael function Wikipedia (CC BY-SA)
- Multiplicative order Wikipedia (CC BY-SA)
- Carmichael number Wikipedia (CC BY-SA)
- Euler's theorem Wikipedia (CC BY-SA)
- Nontotient Wikipedia (CC BY-SA)
- Coprime integers Wikipedia (CC BY-SA)
- Multiplicative group of integers modulo n Wikipedia (CC BY-SA)
- Miller-Rabin primality test Wikipedia (CC BY-SA)
- Pollard's rho algorithm Wikipedia (CC BY-SA)
- Pocklington primality test Wikipedia (CC BY-SA)
- A000010 Euler totient function phi(n) The On-Line Encyclopedia of Integer Sequences (CC BY-SA 4.0)
- A002322 Reduced totient function psi(n) The On-Line Encyclopedia of Integer Sequences (CC BY-SA 4.0)
- A005277 Nontotients The On-Line Encyclopedia of Integer Sequences (CC BY-SA 4.0)
- DLMF 27.2 Functions NIST Digital Library of Mathematical Functions
- BigInt - JavaScript MDN Web Docs (CC BY-SA)
- Web Workers API MDN Web Docs (CC BY-SA)