Skip to content
The Calculatorz
Number theory

Euler’s Totient Function Calculator φ(n)

Compute Euler's totient φ(n) from the prime factorisation, with the Carmichael function, primitive roots, coprime list and an Euler's theorem check.

Number

Values

What is Euler's totient function?

Euler's totient function, written φ(n), is the number of positive whole numbers up to n that are coprime to n, meaning their greatest common divisor with n is 1. It is calculated from the prime factorisation of n and is a central tool in number theory and public-key cryptography.

How to use this calculator

Enter a whole number up to one trillion. Optionally enter a base a to check Euler's theorem, aᵠ⁽ⁿ⁾ mod n. For n up to 200 the calculator also lists the numbers coprime to n.

Formula

If n = p₁^e₁ × p₂^e₂ × … then φ(n) = n × (1 − 1/p₁) × (1 − 1/p₂) × …, the count of integers from 1 to n with no common factor with n. The Carmichael function λ(n) is the least common multiple of λ(pᵉ), where λ(pᵉ) = φ(pᵉ), except λ(2ᵉ) = 2ᵉ⁻² for e ≥ 3.

Terms in the formula

φ(n)
Count of integers 1 to n coprime to n.
p
Each distinct prime factor of n.
λ(n)
Carmichael function, the smallest universal exponent.

Understanding your result

The ratio φ(n) ÷ n shows how many numbers up to n are coprime to it: near 1 for a prime, and smaller for numbers with many small prime factors. φ(n) also gives the length of the cycle in Euler's theorem, so powers of any coprime base repeat every φ(n) steps, or every λ(n) steps.

Calculator credits

Calculator developmentJulia Edwards

Editorial supervision

Expert reviewIfrahMSc Mathematics

Published byThe Calculatorz

Last updated

Read how we research, test, review and correct our calculators in our editorial policy.

Frequently asked questions

What does Euler's totient function count?

φ(n) counts the whole numbers from 1 to n that share no factor with n other than 1. For example φ(9) = 6, because 1, 2, 4, 5, 7 and 8 are coprime to 9.

What is φ of a prime number?

For a prime p, every number from 1 to p − 1 is coprime to it, so φ(p) = p − 1.

What is Euler's theorem?

If a and n are coprime, then a^φ(n) leaves a remainder of 1 when divided by n. Fermat's little theorem is the special case where n is prime.

Where is the totient function used?

In RSA encryption, the private key is found using φ(n) (or λ(n)) of the product of two large primes. It also appears in counting fractions and in modular arithmetic.

What is the Carmichael function?

λ(n) is the smallest exponent that works in Euler's theorem for every a coprime to n. It always divides φ(n) and is often smaller.

Which numbers have a primitive root?

Only 1, 2, 4, powers of an odd prime, and twice a power of an odd prime. For these, λ(n) = φ(n).

References & methodology sources

These sources support the calculator’s formula, definitions, thresholds, units or result interpretation.

  1. Weisstein, E. W. (n.d.). Totient function. MathWorld—A Wolfram Web Resource. View source
  2. OEIS Foundation. (n.d.). A000010: Euler totient function phi(n). The On-Line Encyclopedia of Integer Sequences. View source
  3. Apostol, T. M. (n.d.). Functions: Section 27.2. In NIST Digital Library of Mathematical Functions. National Institute of Standards and Technology. View source
  4. Weisstein, E. W. (n.d.). Euler's totient theorem. MathWorld—A Wolfram Web Resource. View source