CipherMatrix

Euler Totient Function Calculator

Enter a positive integer n to find φ(n), the number of integers from 1 to n that share no common factor with n, with the formula applied step by step.

What is Euler's totient function?

Euler's totient function φ(n) counts the positive integers up to n that are coprime to n, meaning their greatest common divisor with n is 1. For n = 12 the numbers 1, 5, 7 and 11 qualify, so φ(12) = 4. For a prime p every smaller positive integer is coprime to it, so φ(p) = p − 1.

The function appears all over number theory and cryptography. It gives the size of the group of units modulo n, it appears in Euler's theorem, and in RSA the private exponent d is the inverse of the public exponent e modulo φ(n).

The product formula

If n = p₁e₁ p₂e₂ … pₖeₖ, then φ(n) = n × (1 − 1/p₁) × (1 − 1/p₂) × … × (1 − 1/pₖ). Equivalently, φ is multiplicative: φ(ab) = φ(a)φ(b) whenever gcd(a, b) = 1, and for a prime power φ(pe) = pe−1(p − 1). The calculator applies both versions to the prime factorization of n and checks that they agree.

Example: 360 = 23 × 32 × 5, so φ(360) = 4 × 6 × 4 = 96. Using the other form, 360 × (1/2) × (2/3) × (4/5) = 96.

Euler's theorem and RSA

Euler's theorem states that aφ(n) ≡ 1 (mod n) whenever gcd(a, n) = 1. Fermat's little theorem is the special case n = p, where it reads ap−1 ≡ 1 (mod p). In RSA, with n = pq for two primes, φ(n) = (p − 1)(q − 1). Choosing e coprime to φ(n) and d with ed ≡ 1 (mod φ(n)) makes decryption undo encryption, because med = m1 + kφ(n) ≡ m (mod n).

Checking the answer

For n up to 200 000 the calculator also counts the coprime integers directly, one gcd at a time, and confirms the formula. For small n up to 60 it prints the full list of coprime residues so you can compare with a hand count. Larger values rely on the exact formula, which is reliable for any size once n is factored.

Worked examples

These examples are computed by the same engine as the calculator above, so you can compare each step with your own working.

φ(12)

  • Number n: 12
Euler totient φ(12)
4
4 integers from 1 to 12 are coprime to 12
Euler's theorem: a^4 ≡ 1 (mod 12) for every a coprime to 12.

Step-by-step solution

Formula used
φ(n) = n · ∏ (1 − 1/p) over the distinct primes p dividing n
φ(p^e) = p^(e−1)(p − 1), φ(ab) = φ(a)φ(b) if gcd(a, b) = 1
  1. CalculateFactor n into primes
    n = p₁^e₁ × p₂^e₂ × … × pₖ^eₖ
    12 = 2^2 × 3
  2. CalculateApply φ to each prime power
    φ(p^e) = p^(e−1) × (p − 1)
    φ(2^2) = 2^1 × (2 − 1) = 2
    φ(3) = (3 − 1) = 2
  3. CalculateMultiply the results (φ is multiplicative)
    φ(a·b) = φ(a)·φ(b) when gcd(a, b) = 1
    φ(12) = 2 × 2 = 4
  4. CalculateCross-check with the product formula
    φ(n) = n × ∏ (1 − 1/p)
    φ(12) = 12 × (1 − 1/2) × (1 − 1/3)
    = 12 / 6 × 1 × 2 = 4
  5. CheckVerify by counting
    Count the integers k with 1 ≤ k ≤ 12 and gcd(k, 12) = 1: 4 of them.
    They are: 1, 5, 7, 11

φ(360)

  • Number n: 360
Euler totient φ(360)
96
96 integers from 1 to 360 are coprime to 360
Euler's theorem: a^96 ≡ 1 (mod 360) for every a coprime to 360.

Step-by-step solution

Formula used
φ(n) = n · ∏ (1 − 1/p) over the distinct primes p dividing n
φ(p^e) = p^(e−1)(p − 1), φ(ab) = φ(a)φ(b) if gcd(a, b) = 1
  1. CalculateFactor n into primes
    n = p₁^e₁ × p₂^e₂ × … × pₖ^eₖ
    360 = 2^3 × 3^2 × 5
  2. CalculateApply φ to each prime power
    φ(p^e) = p^(e−1) × (p − 1)
    φ(2^3) = 2^2 × (2 − 1) = 4
    φ(3^2) = 3^1 × (3 − 1) = 6
    φ(5) = (5 − 1) = 4
  3. CalculateMultiply the results (φ is multiplicative)
    φ(a·b) = φ(a)·φ(b) when gcd(a, b) = 1
    φ(360) = 4 × 6 × 4 = 96
  4. CalculateCross-check with the product formula
    φ(n) = n × ∏ (1 − 1/p)
    φ(360) = 360 × (1 − 1/2) × (1 − 1/3) × (1 − 1/5)
    = 360 / 30 × 1 × 2 × 4 = 96
  5. CheckVerify by counting
    Count the integers k with 1 ≤ k ≤ 360 and gcd(k, 360) = 1: 96 of them.

Prime: φ(97)

  • Number n: 97
Euler totient φ(97)
96
96 integers from 1 to 97 are coprime to 97
97 is prime, so φ(n) = n − 1 = 96: every smaller positive integer is coprime to it.
Euler's theorem: a^96 ≡ 1 (mod 97) for every a coprime to 97.

Step-by-step solution

Formula used
φ(n) = n · ∏ (1 − 1/p) over the distinct primes p dividing n
φ(p^e) = p^(e−1)(p − 1), φ(ab) = φ(a)φ(b) if gcd(a, b) = 1
  1. CalculateFactor n into primes
    n = p₁^e₁ × p₂^e₂ × … × pₖ^eₖ
    97 = 97
  2. CalculateApply φ to each prime power
    φ(p^e) = p^(e−1) × (p − 1)
    φ(97) = (97 − 1) = 96
  3. CalculateMultiply the results (φ is multiplicative)
    φ(a·b) = φ(a)·φ(b) when gcd(a, b) = 1
    φ(97) = 96 = 96
  4. CalculateCross-check with the product formula
    φ(n) = n × ∏ (1 − 1/p)
    φ(97) = 97 × (1 − 1/97)
    = 97 / 97 × 96 = 96
  5. CheckVerify by counting
    Count the integers k with 1 ≤ k ≤ 97 and gcd(k, 97) = 1: 96 of them.

RSA: φ(3233)

  • Number n: 3233
Euler totient φ(3233)
3120
3120 integers from 1 to 3233 are coprime to 3233
Euler's theorem: a^3120 ≡ 1 (mod 3233) for every a coprime to 3233.

Step-by-step solution

Formula used
φ(n) = n · ∏ (1 − 1/p) over the distinct primes p dividing n
φ(p^e) = p^(e−1)(p − 1), φ(ab) = φ(a)φ(b) if gcd(a, b) = 1
  1. CalculateFactor n into primes
    n = p₁^e₁ × p₂^e₂ × … × pₖ^eₖ
    3233 = 53 × 61
  2. CalculateApply φ to each prime power
    φ(p^e) = p^(e−1) × (p − 1)
    φ(53) = (53 − 1) = 52
    φ(61) = (61 − 1) = 60
  3. CalculateMultiply the results (φ is multiplicative)
    φ(a·b) = φ(a)·φ(b) when gcd(a, b) = 1
    φ(3233) = 52 × 60 = 3120
  4. CalculateCross-check with the product formula
    φ(n) = n × ∏ (1 − 1/p)
    φ(3233) = 3233 × (1 − 1/53) × (1 − 1/61)
    = 3233 / 3233 × 52 × 60 = 3120
  5. CheckVerify by counting
    Count the integers k with 1 ≤ k ≤ 3233 and gcd(k, 3233) = 1: 3120 of them.

Frequently asked questions

What is φ(1)?

φ(1) = 1. The only integer from 1 to 1 is 1 itself, and gcd(1, 1) = 1.

How do I compute φ(n) for a prime power?

Use φ(p^e) = p^(e−1)(p − 1). For example φ(27) = 3² × 2 = 18, and φ(16) = 2³ × 1 = 8.

Why is φ(n) even for n greater than 2?

The numbers coprime to n come in pairs k and n − k, which are always different when n > 2, so their count is even.

Why does RSA need φ(n)?

Because the private exponent d is the modular inverse of e modulo φ(n). Knowing φ(n) is equivalent to knowing the factorization of n, which is why it must stay secret.

Related calculators