Tool to compute Phi: the Euler Totient. Euler's Totient function φ(n) represents the number of integers inferior to n and coprime with n.
Euler's Totient - dCode
Tag(s) : Arithmetics
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
Euler's totient function (or Euler's indicator), noted with the greek letter phi: φ(n) or ϕ(n) an arithmetic function which associates with each strictly positive natural number n, the number of natural numbers between 1 and n that are coprime with n.
Phi(n) (euler indicator) is determined in several ways. The best-known calculation formula for determining the value of the Euler indicator uses the decomposition into prime factors of n. Let pi be the m distinct prime factors that are divisor or n (of multiplicity k). Formula (1) is:
φ(n)=m∏i=1(pi−1)pki−1i(1)
After simplification, another formula (2) is:
φ(n)=nm∏i=1(1−1pi)(2)
Example: For n=12, only 1, 5, 7, 11 are coprime with 12 so φ(12)=4. The prime factor decomposition of 12 is 12=22×31
Formula (1) φ(12)=((2−1)×22−1)×((3−1)×31−1)=2×2=4
Formula (2) φ(12)=12(1−12)(1−13)=12×12×23=12×26=246=4
If n is a prime number, then φ(n)=n−1
Solving ϕ(x)=N requires an optimized search algorithm based on ϕ(x)≥√x2 that tests all values. More details here
Euler totient phi function is used in modular arithmetic. It is used in Euler's theorem:
If n is an integer superior or equal to 1 and a an integer coprime with n, then a^{\varphi(n)} \equiv 1 \mod n
Example: n=7 , a=3 and \varphi(7) = 6 so 3^6 = 729 \equiv 1 \mod 7
This theorem is the basis of the RSA encryption.
The Euler indicator is an essential function of modular arithmetic:
— A positive integer p is a prime number if and only if \varphi(p) = p - 1
— The value \varphi(n) is even for all n > 2
— \varphi(ab) = \varphi(a) \varphi(b) \frac{d}{\varphi(d)} with d the GCD of a and b
— If a and b are coprimes (relatively primes), then \varphi(a \times b) = \varphi(a) \times \varphi(b)
— If a divides b then \varphi(a) \mid \varphi(b)
— If a is even, \varphi(2a) = 2 \varphi(a)
— If a is odd, \varphi(2a) = \varphi(a)
The sequence of values of Phi(n) is 1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8, 16, 6, 18, 8, 12, 10, 22, 8, 20, 12, 18, 12, 28, etc. here
The Euler phi(n) calculation can be coded with an algorithm like:
function phi(n) {
r = n;
for (i = 2; i*i <= n; i++) {
if (n % i == 0) {
r -= r / i;
while (n % i == 0) {
n /= i;
}
}
}
if (n > 1) r -= r / n;
return r;
}
dCode retains ownership of the "Euler's Totient" source code. Any algorithm for the "Euler's Totient" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Euler's Totient" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Euler's Totient" or any other element are not public (except explicit open source licence like Creative Commons). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Euler's Totient" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source.
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Euler's Totient on dCode.fr [online website], retrieved on 2025-04-24,