Euler's Totient
calculator.
Count the whole numbers up to n that share no factor with n, with the working.
- Prime factors
- 2² × 3²
- φ(n) ÷ n
- 13
- n is prime
- No
Only the distinct primes 2 and 3 matter here. Each one removes its share of the numbers, which leaves 33.33% of them coprime to 36.
Numbers from 1 to 36 coprime to 36
12 of the 36 cells are filled: 1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35.
Working
- 1Factor n into primes36 = 2² × 3²
- 2Multiply n by one minus one over each distinct primeφ(36) = 36× (1 −12)× (1 −13)
- 3Or prime power by prime powerφ(2²) = 2 × 1 = 2φ(3²) = 3 × 2 = 6
- 4Multiply the piecesφ(36) = 2 × 6 = 12
- 5Check: φ of every divisor adds back up to n1 + 1 + 2 + 2 + 2 + 6 + 4 + 6 + 12 = 36
Divisors and their totients
| Divisor d | φ(d) |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 2 |
| 6 | 2 |
| 9 | 6 |
| 12 | 4 |
| 18 | 6 |
The φ column adds up to 36, which is n again.
Which numbers have this totient?
6 numbers have a totient of 12: 13, 21, 26, 28, 36, 42.
Euler's theorem and multiplying totients
How it's worked out
Euler's totient, written φ(n) and read "phi of n", counts the whole numbers from 1 to n that are coprime to n. Coprime means the two share no factor except 1. For 12 those numbers are 1, 5, 7, 11, so φ(12) = 4.
Listing works for small n, but a formula is faster. Factor n into primes. Then, for each distinct prime p, multiply n by 1 minus 1 over p. Each factor removes the share of numbers that p divides. How many times a prime repeats does not change the formula.
For 36, the primes are 2 and 3, so φ(36) = 36 × × = 12. You can also work prime power by prime power. A prime power has a short rule of its own, and the pieces multiply.
The pieces multiply because φ is multiplicative: φ(mn) = φ(m) × φ(n) whenever m and n share no factor. Factoring is the hard step. The tool tries divisors up to the square root of n, which is quick for any n up to 10¹².
The working ends with a check from OEIS A000010: add φ(d) over every divisor d of n, and you get n back. When n has too many divisors for that, the check uses Euler's theorem instead.
Worked examples
Hana works out φ(360) for her homework
Hana factors 360 as 2³ × 3² × 5. Its distinct primes are 2, 3 and 5, so she multiplies 360 by , and and gets 96.
Prime power by prime power, the pieces are φ(2³) = 4 × 1 = 4, φ(3²) = 3 × 2 = 6, φ(5) = 1 × 4 = 4. Their product is again 96. As a check, 360 has 24 divisors, and φ of each adds up to 360.
Omar builds a toy RSA key from 61 and 53
In RSA you multiply two primes to make the public number n. Omar uses 61 and 53, so n = 3,233, which factors as 53 × 61. The pieces are φ(53) = 1 × 52 = 52 and φ(61) = 1 × 60 = 60, so φ(3,233) = 3,120.
His two key numbers must multiply to leave 1 when divided by 3,120. Euler's theorem is what makes decryption work: 5 shares no factor with 3,233, and 5 to the power 3,120 leaves 1 when divided by 3,233. Real keys use primes hundreds of digits long, so nobody can factor n to find φ.
Kai lists every number whose totient is 12
Kai's puzzle asks for every n with φ(n) = 12. Only primes p where p − 1 divides 12 can appear in such an n, which leaves 2, 3, 5, 7 and 13. Checking the ways to combine them gives 6 answers: 13, 21, 26, 28, 36, 42.
That matches the list in OEIS A032447. Some values have no answer at all. No n has φ(n) = 14, so the search returns nothing for it, while 8 has 5 answers: 15, 16, 20, 24, 30.
Reading your result
The share depends only on the primes. φ(n) divided by n is the share of numbers coprime to n. For 12 and for 36 it is the same, because both are built from 2 and 3.
Primes score highest. Every number below a prime is coprime to it, so φ(97) = 96. A prime always gives one less than itself.
It is even for every n above 2. OEIS A000010 notes this. If k is coprime to n, so is n − k, and the two are different numbers, so the coprimes come in pairs.
More small primes, smaller share. The table multiplies in one more prime each row. The share coprime to n keeps falling, though slowly.
| n | φ(n) | Share coprime |
|---|---|---|
| 6 | 2 | 33.3% |
| 30 | 8 | 26.7% |
| 210 | 48 | 22.9% |
| 2,310 | 480 | 20.8% |
| 30,030 | 5,760 | 19.2% |
| 510,510 | 92,160 | 18.1% |
Common mistakes
- Using the exponents in the product. For 36 = 2² × 3² you use each prime once, not twice. The answer is 12, not 36 × × .
- Multiplying totients of numbers that share a factor. φ(4) = 2, but φ(2) × φ(2) = 1. The rule needs no shared factor, as with 9 and 4: φ(36) = 12 = 2 × 6.
- Leaving out 1. One shares no factor with any number, so it always counts, and φ(1) = 1.
- Using Euler's theorem when a and n share a factor. With a = 4 and n = 12 they share 4, so no power of 4 leaves 1 when divided by 12. Check that the two are coprime first.