Number Theory
Advanced

Euler's Totient

Counts integers up to n coprime to n.

Formula

ϕ(n)=n∏p∣n(1−1p)\phi(n) = n\prod_{p|n}\left(1 - \frac{1}{p}\right)

Variables

nPositive integer
pPrime divisors

Example

φ(12) = 4

How it works

Euler’s totient function counts how many integers from 1 to n have no common factor with n other than 1. The product formula works because for each prime divisor p of n, exactly a 1/p fraction of the numbers up to n are multiples of p, so removing those multiples for every distinct prime factor leaves the count of numbers coprime to n. This is an inclusion-exclusion result in compact multiplicative form.

When to use it

Use this when you need the size of the reduced residue system modulo n, especially in modular arithmetic, RSA, and other number-theory problems involving coprimality. It is also useful for simplifying expressions like a^φ(n) mod n when using Euler’s theorem.

Worked example, step by step

Find φ(18). 18 = 2 × 3^2, so the distinct prime divisors are 2 and 3. Apply the formula: φ(18) = 18(1 - 1/2)(1 - 1/3) Compute each factor: φ(18) = 18 × 1/2 × 2/3 Multiply: φ(18) = 18 × 1/3 = 6 So, φ(18) = 6.

Common mistakes to avoid

  • Using repeated prime factors more than once; only distinct prime divisors appear in the product
  • Forgetting that the formula applies to positive integers n, not to individual prime powers directly unless factored first
  • Assuming φ(n) counts numbers not divisible by any prime dividing n, instead of numbers that are coprime to n

Did You Know?

Euler's totient counts the numbers coprime to n — the secret sauce inside RSA key generation.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026