In number theory, Euler's totient function counts the positive integers up to a given integer n that are relatively prime to n. It is written using the Greek letter phi as φ(n) or ϕ(n), and may also be called Euler's phi function. In other words, it is the number of integers k in the range 1≤k≤n for which the greatest common divisor gcd(n,k) is equal to 1. The integers k of this form are sometimes referred to as totatives of n. For example, the totatives of n=9 are the six numbers 1, 2, 4, 5, 7 and 8. They are all relatively prime to 9, but the other three numbers in this range, 3, 6, and 9 are not, since gcd(9,3)=gcd(9,6)=3 and gcd(9,9)=9. Therefore, φ(9)=6. As another example, φ(1)=1 since for n=1 the only integer in the range from 1 to n is 1 itself, and gcd(1,1)=1. Euler's totient function is a multiplicative function, meaning that if two numbers m and n are relatively prime, then φ(mn)=φ(m)φ(n). This function gives the order of the multiplicative group of integers modulo n (the group of units of the ring ℤ/nℤ). It is also used for defining the RSA encryption system.
History, terminology, and notation Leonhard Euler introduced the function in 1763. However, he did not at that time choose any specific symbol to denote it. In a 1784 publication, Euler studied the function further, choosing the Greek letter π to denote it: he wrote πD for "the multitude of numbers less than D, and which have no common divisor with it". This definition varies from the current definition for the totient function at D=1 but is otherwise the same. The now-standard notation φ(A) comes from Gauss's 1801 treatise Disquisitiones Arithmeticae, although Gauss did not use parentheses around the argument and wrote φA. Thus, it is often called Euler's phi function or simply the phi function. In 1879, J. J. Sylvester coined the term totient for this function, so it is also referred to as Euler's totient function, the Euler totient, or Euler's totient. Jordan's totient is a generalization of Euler's. The cototient of n is defined as n−φ(n). It counts the number of positive integers less than or equal to n that have at least one prime factor in common with n.
Computing Euler's totient function There are several formulae for computing φ(n).
Euler's product formula It states φ(n)=n∏p∣n(1−1p), where the product is over the distinct prime numbers dividing n. An equivalent formulation is φ(n)=p1k1−1(p1−1)p2k2−1(p2−1)⋯prkr−1(pr−1), where n=p1k1p2k2⋯prkr is the prime factorization of n (that is, p1,p2,…,pr are distinct prime numbers). The proof of these formulae depends on two important facts.
Phi is a multiplicative function This means that if gcd(m,n)=1, then φ(m)φ(n)=φ(mn). Proof outline: Let A,B,C be the sets of positive integers which are coprime to and less than m, n, mn, respectively, so that |A|=φ(m), etc. Then there is a bijection between A×B and C by the Chinese remainder theorem.
Value of phi for a prime power argument If p is prime and k≥1, then φ(pk)=pk−pk−1=pk−1(p−1)=pk(1−1p). Proof: Since p is a prime number, the only possible values of gcd(pk,m) are 1,p,p2,…,pk, and the only way to have gcd(pk,m)>1 is if m is a multiple of p, that is, m∈{p,2p,3p,…,pk−1p=pk}, and there are pk−1 such multiples not greater than pk. Therefore, the other pk−pk−1 numbers are all relatively prime to pk.
Proof of Euler's product formula The fundamental theorem of arithmetic states that if n > 1 there is a unique expression n=p1k1p2k2⋯prkr, where p1 < p2 < ... < pr are prime numbers and each ki ≥ 1. (The case n = 1 corresponds to the empty product.) Repeatedly using the multiplicative property of φ and the formula for φ(pk) gives φ(n)=φ(p1k1)φ(p2k2)⋯φ(prkr)=p1k1(1−1p1)p2k2(1−1p2)⋯prkr(1−1pr)=p1k1p2k2⋯prkr(1−1p1)(1−1p2)⋯(1−1pr)=n(1−1p1)(1−1p2)⋯(1−1pr). This gives both versions of Euler's product formula. An alternative proof that does not require the multiplicative property instead uses the inclusion-exclusion principle applied to the set {1,2,…,n}, excluding the sets of integers divisible by the prime divisors.
Example φ(20)=φ(225)=20(1−12)(1−15)=20⋅12⋅45=8. In words: the distinct prime factors of 20 are 2 and 5; half of the twenty integers from 1 to 20 are divisible by 2, leaving ten; a fifth of those are divisible by 5, leaving eight numbers coprime to 20; these are: 1, 3, 7, 9, 11, 13, 17, 19. The alternative formula uses only integers:φ(20)=φ(2251)=22−1(2−1)51−1(5−1)=2⋅1⋅1⋅4=8.
Fourier transform The totient is the discrete Fourier transform of the gcd, evaluated at 1. Let ℱ{𝐱}[m]=∑k=1nxk⋅e−2πimkn where xk = gcd(k,n) for k ∈ {1, ..., n}. Then φ(n)=ℱ{𝐱}[1]=∑k=1ngcd(k,n)e−2πikn. The real part of this formula is φ(n)=∑k=1ngcd(k,n)cos2πkn. For example, using cosπ5=5+14 and cos2π5=5−14:φ(10)=gcd(1,10)cos2π10+gcd(2,10)cos4π10+gcd(3,10)cos6π10+⋯+gcd(10,10)cos20π10=1⋅(5+14)+2⋅(5−14)+1⋅(−5−14)+2⋅(−5+14)+5⋅(−1)+ 2⋅(−5+14)+1⋅(−5−14)+2⋅(5−14)+1⋅(5+14)+10⋅(1)=4.Unlike the Euler product and the divisor sum formula, this one does not require knowing the factors of n. However, it does involve the calculation of the greatest common divisor of n and every positive integer less than n, which suffices to provide the factorization anyway.
… excerpt ends here. Continue reading the full article.

![Euler's totient function: The first thousand values of .mw-parser-output .texhtml{font-family:"Nimbus Roman No9 L","Times New Roman",Times,serif;font-size:118%;line-height:1;font-variant-numeric:lining-nums tabular-nums;font-kerning:none}.mw-parser-output .texhtml .texhtml{font-size:100%}.mw-parser-output .texhtml-big{font-size:165%}.mw-parser-output .mvar{font-style:italic}@media(min-width:420px){.mw-parser-output .texhtml{white-space:nowrap}}φ(n). The points on the top line represent φ(p) when p is a prime number, which is p − 1.[1]](https://thumb.wikimedia.org/wikipedia/commons/thumb/9/9b/EulerPhi.svg/1280px-EulerPhi.svg.png?utm_source=en.wikipedia.org&utm_campaign=parser&utm_content=thumbnail)
