Skip to main content

Interactive Math Workbooks

Practice, learn and master mathematics with interactive exercises and instant feedback.

Euler's Totient Calculator

Mathematics - Euler's Totient Function

Euler's Totient Calculator — Calculate φ(n) with Step-by-Step Explanation

Calculate Euler's totient function φ(n) for any positive integer with step-by-step explanation. Learn the formula using prime factorization, understand coprime counting, and explore applications in number theory. For related number theory tools, see our prime factorization calculator.

Calculate φ(n)

Enter a positive integer to calculate Euler's totient function φ(n). Click Calculate for step-by-step working.

φ(n) will appear here.
Note: Euler's totient function φ(n) counts the number of positive integers up to n that are coprime to n (share no common factors with n other than 1). It's a fundamental function in number theory and the mathematical foundation of RSA cryptography.

Euler's Totient Function – Complete Explanation

Euler's totient function φ(n) (also called Euler's phi function) counts the number of positive integers up to n that are coprime to n — meaning they share no common factors with n other than 1. This function is central to number theory and forms the mathematical foundation of RSA cryptography.

Euler's Totient Function

φ(n) = number of integers k (1 ≤ k ≤ n) such that GCD(k, n) = 1

φ(1) = 1 by definition.

1. What Is Euler's Totient Function?

The totient φ(n) answers the question: "How many numbers up to n are relatively prime to n?" Two numbers are relatively prime (coprime) if their greatest common divisor is 1.

Key facts:

  • φ(1) = 1: By definition.
  • φ(p) = p - 1: For any prime p, all numbers from 1 to p-1 are coprime to p.
  • φ(pᵏ) = pᵏ - pᵏ⁻¹: For a prime power, subtract the multiples of p.
  • φ is multiplicative: If a and b are coprime, then φ(ab) = φ(a) × φ(b).

2. The Totient Formula

The most efficient way to calculate φ(n) uses the prime factorization of n:

Totient Product Formula

φ(n) = n × Π(1 - 1/p)  for each distinct prime p dividing n

Equivalently: φ(n) = n × ((p₁-1)/p₁) × ((p₂-1)/p₂) × ...

This formula works because:

  • Start with n numbers (1 through n).
  • For each prime p dividing n, the fraction 1/p of numbers are multiples of p and must be removed.
  • The factor (1 - 1/p) keeps the fraction that are NOT multiples of p.
  • These fractions multiply because the conditions are independent for different primes.

3. How to Calculate φ(n)

The systematic approach:

  1. Find the prime factorization of n.
  2. Identify the distinct primes that divide n.
  3. Apply the formula: φ(n) = n × Π(1 - 1/p) for each distinct prime p.
  4. Alternatively, count the numbers from 1 to n that are coprime to n.
Efficiency: The product formula is much faster than counting for large n because it only requires knowing the distinct prime factors.

4. Step-by-Step Examples

Example 1: φ(12)

Calculate φ(12).

Step 1: Prime factorize 12:
        12 = 2 × 2 × 3 = 2² × 3
        Distinct primes: 2 and 3

Step 2: Apply the formula:
        φ(12) = 12 × (1 - 1/2) × (1 - 1/3)
              = 12 × (1/2) × (2/3)
              = 12 × 1/3
              = 4

Verification: Numbers ≤ 12 coprime to 12: 1, 5, 7, 11 → 4 ✓

Result: φ(12) = 4

Example 2: φ(36)

Calculate φ(36).

Step 1: 36 = 2² × 3²
        Distinct primes: 2 and 3

Step 2: φ(36) = 36 × (1-1/2) × (1-1/3)
              = 36 × (1/2) × (2/3)
              = 36 × 1/3
              = 12

Result: φ(36) = 12

5. More Totient Examples

φ(7) = 6 — 7 is prime, so φ(7) = 7 - 1

φ(8) = 4 — coprime: 1, 3, 5, 7

φ(9) = 6 — coprime: 1, 2, 4, 5, 7, 8

φ(10) = 4 — coprime: 1, 3, 7, 9

φ(100) = 40 — 100 × (1-1/2) × (1-1/5) = 100 × 1/2 × 4/5 = 40

6. Totient of Prime Numbers

For a prime number p, the totient is beautifully simple:

Totient of a Prime

φ(p) = p - 1  (for any prime p)

All numbers from 1 to p-1 are coprime to p.

For a prime power pᵏ:

φ(pᵏ) = pᵏ - pᵏ⁻¹ = pᵏ⁻¹(p - 1)

Example: φ(8) = φ(2³) = 2³ - 2² = 8 - 4 = 4

Example: φ(27) = φ(3³) = 3³ - 3² = 27 - 9 = 18

7. Euler's Theorem

Euler's totient function is famous because of Euler's theorem:

Euler's Theorem

If GCD(a, n) = 1, then aφ(n) ≡ 1 (mod n)

This generalizes Fermat's Little Theorem to composite moduli.

Example with n = 12 (φ(12) = 4):

Choose a = 5: 5⁴ = 625 = 52×12 + 1 → 625 ≡ 1 (mod 12) ✓

Choose a = 7: 7⁴ = 2401 = 200×12 + 1 → 2401 ≡ 1 (mod 12) ✓

8. Properties of φ(n)

Multiplicative: If GCD(a, b) = 1, then φ(ab) = φ(a) × φ(b).

Example: φ(3) = 2, φ(4) = 2, φ(12) = 4 = 2 × 2 ✓

Sum Property: Σ φ(d) = n, where d runs over all divisors of n.

Example: n = 12: φ(1)+φ(2)+φ(3)+φ(4)+φ(6)+φ(12) = 1+1+2+2+2+4 = 12 ✓

Even for n > 2: φ(n) is always even when n > 2.

Lower Bound: φ(n) ≥ √n for n ≥ 6 (approximately).

9. Common Mistakes to Avoid

  • Forgetting that φ(1) = 1: Special case — the product formula doesn't apply.
  • Counting composite numbers as coprime: Only numbers with GCD = 1 count.
  • Using the wrong formula for prime powers: φ(pᵏ) = pᵏ - pᵏ⁻¹, not pᵏ - 1.
  • Confusing totient with number of factors: φ(12) = 4, but 12 has 6 factors.
  • Applying multiplicative property incorrectly: Only when a and b are coprime.

10. Real-World Applications

  • RSA Cryptography: The security of RSA encryption relies on Euler's totient. Keys are derived using φ(n) where n is the product of two large primes.
  • Digital Signatures: RSA signatures use Euler's theorem to verify authenticity.
  • Modular Exponentiation: Euler's theorem simplifies large modular computations.
  • Random Number Generation: The multiplicative group modulo n (with φ(n) elements) is used in PRNGs.
  • Mathematics: φ(n) appears in cyclotomic polynomials, primitive roots, and group theory.
  • Competitive Programming: Totient-based solutions for modular arithmetic problems.

11. Practice Problems with Solutions

Problem 1: Calculate φ(15).

Solution: 15 = 3 × 5 → φ(15) = 15 × 2/3 × 4/5 = 8

Problem 2: Calculate φ(20).

Solution: 20 = 2² × 5 → φ(20) = 20 × 1/2 × 4/5 = 8

Problem 3: If p = 17 is prime, what is φ(17)?

Solution: φ(17) = 17 - 1 = 16

Problem 4: Verify Euler's theorem for a = 3, n = 10.

Solution: φ(10) = 4 | 3⁴ = 81 = 8×10 + 1 → 81 ≡ 1 (mod 10) ✓

12. Tips for Mastering the Totient

  • Memorize the product formula: φ(n) = n × Π(1 - 1/p) for distinct primes p | n.
  • For prime numbers, φ(p) = p - 1 — instant and simple.
  • For prime powers, φ(pᵏ) = pᵏ⁻¹(p - 1).
  • Use the multiplicative property to break composite numbers into coprime factors.
  • Always verify that φ(n) < n (for n > 1).
  • Practice connecting φ(n) to Euler's theorem — it's the most important application.

13. Final Thoughts

Euler's totient function is one of the most elegant and powerful concepts in number theory. It counts what can't be divided, measures the "relative primeness" of numbers, and provides the mathematical foundation for the cryptography that secures the modern internet. From its simple definition — counting coprime numbers — flows Euler's theorem, modular arithmetic, and the RSA algorithm that protects billions of digital transactions daily.

Understanding φ(n) opens the door to advanced number theory, abstract algebra, and cryptography. Use this calculator to explore totient values and verify your manual calculations, but practice applying the product formula until it becomes intuitive and automatic.

14. Frequently Asked Questions

Euler's totient function φ(n) counts the number of positive integers up to n that are coprime to n — they share no common factors with n other than 1. For example, φ(12) = 4 because the numbers 1, 5, 7, and 11 are the only numbers up to 12 that are coprime to 12.

First, find the prime factorization of n. Then apply the formula: φ(n) = n × Π(1 - 1/p) for each distinct prime p dividing n. For example, φ(12) = 12 × (1-1/2) × (1-1/3) = 12 × 1/2 × 2/3 = 4.

For a prime number p, φ(p) = p - 1. This is because all numbers from 1 to p-1 are coprime to p (a prime has no factors other than 1 and itself). For example, φ(7) = 6, φ(13) = 12, and φ(1000003) = 1000002.

Euler's theorem states: If GCD(a, n) = 1, then aφ(n) ≡ 1 (mod n). This is a generalization of Fermat's Little Theorem to composite moduli. It's used in RSA encryption and modular arithmetic simplifications.

Yes, φ(n) is always even for n > 2. This is because φ(n) counts numbers coprime to n, and for every number k that is coprime to n, the number n - k is also coprime to n. These pair up, resulting in an even count. The only exceptions are φ(1) = 1 (odd) and φ(2) = 1 (odd).

The totient is multiplicative: if GCD(a, b) = 1, then φ(ab) = φ(a) × φ(b). This allows breaking composite numbers into coprime factors for easier calculation. However, this only works when the factors are coprime — φ(4 × 6) ≠ φ(4) × φ(6) because 4 and 6 share the factor 2.

In RSA, two large primes p and q are multiplied to get n. The totient φ(n) = (p-1)(q-1) is computed. The public key e and private key d are chosen such that e × d ≡ 1 (mod φ(n)). The security of RSA depends on the fact that computing φ(n) requires knowing p and q, which is computationally infeasible for large n.

Explore Math Topics

Continue your learning journey with our other math guides

Related Calculators

Explore these other math tools that complement Euler's totient:

Conclusion

Euler's totient function is one of the most elegant and powerful concepts in number theory. Use this calculator to explore totient values and verify your manual calculations, but practice applying the product formula until it becomes intuitive and automatic.

Readers who wish to continue practicing and reinforce what they've learned can explore the companion learning resource for guided exercises.