maths.freeNumber Theory › Congruences › Euler's totient function

Euler's totient function

In number theory, Euler's totient function counts the positive integers up to a given integer that are relatively prime to . It is written using the Greek letter phi as or , and may also be called Euler's phi function.

Euler's totient function

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 \(\varphi(n)\) or \(\phi(n)\), and may also be called Euler's phi function. In other words, it is the number of integers \(k\) in the range \(1\leq k\leq 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, \(\varphi(9)=6\). As another example, \(\varphi(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 \(\varphi(mn)=\varphi(m)\varphi(n)\). This function gives the order of the multiplicative group of integers modulo n (the group of units of the ring \(\Z/n\Z\)). 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 \(\pi\) to denote it: he wrote \(\pi 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 \(\varphi(A)\) comes from Gauss's 1801 treatise Disquisitiones Arithmeticae, although Gauss did not use parentheses around the argument and wrote \(\varphi 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-\varphi(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\).

Euler's product formula

It states

\(\varphi(n) =n \prod_{p\mid n} \left(1-\frac{1}{p}\right),\)

where the product is over the distinct prime numbers dividing n.

An equivalent formulation is

\(\varphi(n) = p_1^{k_1-1}(p_1{-}1)\,p_2^{k_2-1}(p_2{-}1)\cdots p_r^{k_r-1}(p_r{-}1),\)

where \(n = p_1^{k_1} p_2^{k_2} \cdots p_r^{k_r}\) is the prime factorization of \(n\) (that is, \(p_1, p_2,\ldots, p_r\) are distinct prime numbers).

The proof of these formulae depends on two important facts.

Fourier transform

The totient is the discrete Fourier transform of the gcd, evaluated at 1. Let

\(\mathcal{F} \{ \mathbf{x} \}[m] = \sum\limits_{k=1}^n x_k \cdot e^{{-2\pi i}\frac{mk}{n}}\)

where xk = gcd(k,n) for k ∈ {1, ..., n}. Then

\(\varphi (n) = \mathcal{F} \{ \mathbf{x} \}[1] = \sum\limits_{k=1}^n \gcd(k,n) e^{-2\pi i\frac{k}{n}}.\)

The real part of this formula is

\(\varphi (n)=\sum\limits_{k=1}^n \gcd(k,n) \cos {\tfrac{2\pi k}{n}} .\)

For example, using \(\cos\tfrac{\pi}5 = \tfrac{\sqrt 5+1}4\) and \(\cos\tfrac{2\pi}5 = \tfrac{\sqrt 5-1}4\):\[\begin{array}{rcl} \varphi(10) &=& \gcd(1,10)\cos\tfrac{2\pi}{10} + \gcd(2,10)\cos\tfrac{4\pi}{10} + \gcd(3,10)\cos\tfrac{6\pi}{10}+\cdots+\gcd(10,10)\cos\tfrac{20\pi}{10}\\ &=& 1\cdot(\tfrac{\sqrt5+1}4) + 2\cdot(\tfrac{\sqrt5-1}4) + 1\cdot(-\tfrac{\sqrt5-1}4) + 2\cdot(-\tfrac{\sqrt5+1}4) + 5\cdot (-1) \\ && +\ 2\cdot(-\tfrac{\sqrt5+1}4) + 1\cdot(-\tfrac{\sqrt5-1}4) + 2\cdot(\tfrac{\sqrt5-1}4) + 1\cdot(\tfrac{\sqrt5+1}4) + 10 \cdot (1) \\ &=& 4 . \end{array}\]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.

Divisor sum

The property established by Gauss, that

\(\sum_{d\mid n}\varphi(d)=n,\)

where the sum is over all positive divisors d of n, can be proven in several ways. (See Arithmetical function for notational conventions.)

One proof is to note that φ(d) is also equal to the number of possible generators of the cyclic group Cd ; specifically, if Cd = ⟨g⟩ with g = 1, then g is a generator for every k coprime to d. Since every element of Cn generates a cyclic subgroup, and each subgroup CdCn is generated by precisely φ(d) elements of Cn, the formula follows. Equivalently, the formula can be derived by the same argument applied to the multiplicative group of the nth roots of unity and the primitive dth roots of unity.

The formula can also be derived from elementary arithmetic. For example, let n = 20 and consider the positive fractions up to 1 with denominator 20:

\(\tfrac{ 1}{20},\,\tfrac{ 2}{20},\,\tfrac{ 3}{20},\,\tfrac{ 4}{20},\, \tfrac{ 5}{20},\,\tfrac{ 6}{20},\,\tfrac{ 7}{20},\,\tfrac{ 8}{20},\, \tfrac{ 9}{20},\,\tfrac{10}{20},\,\tfrac{11}{20},\,\tfrac{12}{20},\, \tfrac{13}{20},\,\tfrac{14}{20},\,\tfrac{15}{20},\,\tfrac{16}{20},\, \tfrac{17}{20},\,\tfrac{18}{20},\,\tfrac{19}{20},\,\tfrac{20}{20}.\)

Put them into lowest terms:

\(\tfrac{ 1}{20},\,\tfrac{ 1}{10},\,\tfrac{ 3}{20},\,\tfrac{ 1}{ 5},\, \tfrac{ 1}{ 4},\,\tfrac{ 3}{10},\,\tfrac{ 7}{20},\,\tfrac{ 2}{ 5},\, \tfrac{ 9}{20},\,\tfrac{ 1}{ 2},\,\tfrac{11}{20},\,\tfrac{ 3}{ 5},\, \tfrac{13}{20},\,\tfrac{ 7}{10},\,\tfrac{ 3}{ 4},\,\tfrac{ 4}{ 5},\, \tfrac{17}{20},\,\tfrac{ 9}{10},\,\tfrac{19}{20},\,\tfrac{1}{1}\)

These twenty fractions are all the positive ⁠k/d⁠ ≤ 1 whose denominators are the divisors d = 1, 2, 4, 5, 10, 20. The fractions with 20 as denominator are those with numerators relatively prime to 20, namely ⁠1/20⁠, ⁠3/20⁠, ⁠7/20⁠, ⁠9/20⁠, ⁠11/20⁠, ⁠13/20⁠, ⁠17/20⁠, ⁠19/20⁠; by definition this is φ(20) fractions. Similarly, there are φ(10) fractions with denominator 10, and φ(5) fractions with denominator 5, etc. Thus the set of twenty fractions is split into subsets of size φ(d) for each d dividing 20. A similar argument applies for any n.

Möbius inversion applied to the divisor sum formula gives

\(\varphi(n) = \sum_{d\mid n} \mu\left( d \right) \cdot \frac{n}{d} = n\sum_{d\mid n} \frac{\mu (d)}{d},\)

Condensed: the full section is in Wikipedia.

Some values

The first 100 values (sequence A000010 in the OEIS) are shown in the table and graph below:

In the graph at right the top line y = n − 1 is an upper bound valid for all n other than one, and attained if and only if n is a prime number. A simple lower bound is \(\varphi(n) \ge \sqrt{n/2}\), which is rather loose: in fact, the lower limit of the graph is proportional to ⁠n/log log n⁠.

Euler's theorem

This states that if a and n are relatively prime then

\(a^{\varphi(n)} \equiv 1\mod n.\)

The special case where n is prime is known as Fermat's little theorem.

This follows from Lagrange's theorem and the fact that φ(n) is the order of the multiplicative group of integers modulo n.

The RSA cryptosystem is based on this theorem: it implies that the inverse of the function aa mod n, where e is the (public) encryption exponent, is the function bb mod n, where d, the (private) decryption exponent, is the multiplicative inverse of e modulo φ(n). The difficulty of computing φ(n) without knowing the factorization of n is thus the difficulty of computing d: this is known as the RSA problem which can be solved by factoring n. The owner of the private key knows the factorization, since an RSA private key is constructed by choosing n as the product of two (randomly chosen) large primes p and q. Only n is publicly disclosed, and given the difficulty to factor large numbers we have the guarantee that no one else knows the factorization.

Other formulae

  • \(a\mid b \implies \varphi(a)\mid\varphi(b)\)
  • \(m \mid \varphi(a^m-1)\)
  • \(\varphi(mn) = \varphi(m)\varphi(n)\cdot\frac{d}{\varphi(d)} \quad\text{where }d = \operatorname{gcd}(m,n)\)
    • In particular:
  • \(\varphi(2m) = \begin{cases} 2\varphi(m) &\text{ if } m \text{ is even} \\ \varphi(m) &\text{ if } m \text{ is odd} \end{cases}\)
  • \(\varphi\left(n^m\right) = n^{m-1}\varphi(n)\)
  • \(\varphi(\operatorname{lcm}(m,n))\cdot\varphi(\operatorname{gcd}(m,n)) = \varphi(m)\cdot\varphi(n)\)

Compare this to the formula \(\operatorname{lcm}(m,n)\cdot \operatorname{gcd}(m,n) = m \cdot n\) (see least common multiple).

  • φ(n) is even for n ≥ 3.
    Moreover, if n has r distinct odd prime factors, 2 | φ(n)
  • For any a > 1 and n > 6 such that 4 ∤ n there exists an l ≥ 2n such that l | φ(a − 1).
  • \(\frac{\varphi(n)}{n}=\frac{\varphi(\operatorname{rad}(n))}{\operatorname{rad}(n)}\)

where rad(n) is the radical of n (the product of all distinct primes dividing n).

  • \(\sum_{d \mid n} \frac{\mu^2(d)}{\varphi(d)} = \frac{n}{\varphi(n)}\) 
  • \(\sum_{1\le k\le n-1 \atop gcd(k,n)=1}\!\!k = \tfrac12 n\varphi(n) \quad \text{for }n>1\)
  • \(\sum_{k=1}^n\varphi(k) = \tfrac12 \left(1+ \sum_{k=1}^n \mu(k)\left\lfloor\frac{n}{k}\right\rfloor^2\right) =\frac3{\pi^2}n^2+O\left(n(\log n)^\frac23(\log\log n)^\frac43\right)\) ( cited in)
  • \(\sum_{k=1}^n\varphi(k) =\frac3{\pi^2}n^2+O\left(n(\log n)^\frac23(\log\log n)^\frac13\right)\) [Liu (2016)]
  • \(\sum_{k=1}^n\frac{\varphi(k)}{k} = \sum_{k=1}^n\frac{\mu(k)}{k}\left\lfloor\frac{n}{k}\right\rfloor=\frac6{\pi^2}n+O\left((\log n)^\frac23(\log\log n)^\frac43\right)\) 
  • \(\sum_{k=1}^n\frac{\varphi(k)}{k^2}=\frac{6}{\pi^2}\log n + \frac{6\gamma}{\pi^2}-\frac{\zeta'(2)}{\zeta(2)^2}+O\left(\frac{\log n}{n}\right)\)
  • \(\sum_{k=1}^n\frac{k}{\varphi(k)} = \frac{315\,\zeta(3)}{2\pi^4}n-\frac{\log n}2+O\left((\log n)^\frac23\right)\) 
  • \(\sum_{k=1}^n\frac{1}{\varphi(k)} = \frac{315\,\zeta(3)}{2\pi^4}\left(\log n+\gamma-\sum_{p\text{ prime}}\frac{\log p}{p^2-p+1}\right)+O\left(\frac{(\log n)^\frac23}n\right)\) 
    (where γ is the Euler-Mascheroni constant).

Menon's identity

In 1965 P. Kesava Menon proved

\(\sum_{\stackrel{1\le k\le n}{ \gcd(k,n)=1}} \!\!\!\! \gcd(k-1,n)=\varphi(n)d(n),\)

where d(n) = σ0(n) is the number of divisors of n.

Divisibility by any fixed positive integer

The following property, which is unpublished as a specific result but has long been known, has important consequences. For instance it rules out uniform distribution of the values of \(\varphi(n)\) in the arithmetic progressions modulo \(q\) for any integer \(q>1\).

  • For every fixed positive integer \(q\), the relation \(q|\varphi(n)\) holds for almost all \(n\), meaning for all but \(o(x)\) values of \(n\le x\) as \(x\rightarrow\infty\).

This is an elementary consequence of the fact that the sum of the reciprocals of the primes congruent to 1 modulo \(q\) diverges, which itself is a corollary of the proof of Dirichlet's theorem on arithmetic progressions.

Generating functions

The Dirichlet series for φ(n) may be written in terms of the Riemann zeta function as:

\(\sum_{n=1}^\infty \frac{\varphi(n)}{n^s}=\frac{\zeta(s-1)}{\zeta(s)}\)

where the left-hand side converges for \(\Re (s)>2\).

The Lambert series generating function is

\(\sum_{n=1}^{\infty} \frac{\varphi(n) q^n}{1-q^n}= \frac{q}{(1-q)^2}\)

which converges for |q| < 1.

Both of these are proved by elementary series manipulations and the formulae for φ(n).

Growth rate

In the words of Hardy & Wright, the order of φ(n) is "always 'nearly n'."

First

\(\lim\sup \frac{\varphi(n)}{n}= 1,\)

but as n goes to infinity, for all δ > 0

\(\frac{\varphi(n)}{n^{1-\delta}}\rightarrow\infty.\)

These two formulae can be proved by using little more than the formulae for φ(n) and the divisor sum function σ(n).

In fact, during the proof of the second formula, the inequality

\(\frac {6}{\pi^2} < \frac{\varphi(n) \sigma(n)}{n^2} < 1,\)

true for n > 1, is proved.

We also have

\(\lim\inf\frac{\varphi(n)}{n}\log\log n = e^{-\gamma}.\)

\(\lim\inf\frac{\varphi(n)}{n}= 0.\)

\(\varphi(n) > \frac {n} {e^\gamma\; \log \log n + \frac {3} {\log \log n}} \quad\text{for } n>2\)

\(\varphi(n) < \frac {n} {e^{ \gamma}\log \log n} \quad\text{for infinitely many } n.\)

\(\varphi(1)+\varphi(2)+\cdots+\varphi(n) = \frac{3n^2}{\pi^2}+O\left(n(\log n)^\frac23(\log\log n)^\frac43\right) \quad\text{as }n\rightarrow\infty,\)

\(O\left(n(\log n)^\frac23(\log\log n)^\frac13\right)\)

Condensed: the full section is in Wikipedia.

Ratio of consecutive values

In 1950 Somayajulu proved

\(\begin{aligned} \lim\inf \frac{\varphi(n+1)}{\varphi(n)}&= 0 \quad\text{and} \\[5px] \lim\sup \frac{\varphi(n+1)}{\varphi(n)}&= \infty. \end{aligned}\)

In 1954 Schinzel and Sierpiński strengthened this, proving that the set

\(\left\{\frac{\varphi(n+1)}{\varphi(n)},\;\;n = 1,2,\ldots\right\}\)

is dense in the positive real numbers. They also proved that the set

\(\left\{\frac{\varphi(n)}{n},\;\;n = 1,2,\ldots\right\}\)

is dense in the interval (0,1).

Totient number

A totient number is a value of Euler's totient function: that is, an m for which there is at least one n for which φ(n) = m. The valency or multiplicity of a totient number m is the number of solutions to this equation. A nontotient is a natural number which is not a totient number. Every odd integer exceeding 1 is trivially a nontotient. There are also infinitely many even nontotients, and indeed every positive integer has a multiple which is an even nontotient.

The first few totient numbers are \(1, 2, 4, 6, 8, 10, 12, 16, 18, 20\), see sequence A002202.

The number of totient numbers up to a given limit x is

\(\frac{x}{\log x}e^{ \big(C+o(1)\big)(\log\log\log x)^2 }\)

for a constant C = 0.8178146....

If counted accordingly to multiplicity, the number of totient numbers up to a given limit x is

\(\Big\vert\{ n : \varphi(n) \le x \}\Big\vert = \frac{\zeta(2)\zeta(3)}{\zeta(6)} \cdot x + R(x)\)

where the error term R is of order at most ⁠x/(log x)⁠ for any positive k.

It is known that the multiplicity of m exceeds m infinitely often for any δ < 0.55655.

Ҳоло шумо Ҳеҷ ҳисобкунак инро ҳал намекунад, лекин қисмҳои он ҳисобшавандаанд. Яке аз инҳоро дар поён санҷед ё худи худро ворид кунед.

Кор кардан

Дар ҳисоби ройгон ба ҳар як дарс қайдҳо илова карда мешаванд, қайди он, ки шумо чӣ кор кардаед, масъалаҳои ҳалшуда дар як ҷо ва муаллиме, ки шумо метавонед дар бораи ин саҳифа пурсед. Математика барои ҳама кушода аст, хоҳ ворид шуда бошад ё на.

Бақайдгирӣ Ворид шудан

Символы, используемые здесь

Барои муайянкунии пурраи маъно, тасвир ва маънои ҳар як ҳарф дар он, ба ҳар як аломат пахш кунед.

Саволҳои маъмул

Why are primes so important?

Every integer factors into primes in exactly one way, so primes are the atoms of multiplication. Cryptography relies on that factoring being easy to state and hard to do.

How do I tell whether a big number is prime?

Trial division up to the square root works for small numbers. For large ones, probabilistic tests (Miller-Rabin) give an answer that is wrong with negligible probability, and deterministic tests (AKS) exist but are slower.

Қисми ин саҳифа аз Wikipedia (CC BY-SA 4.0). Дар ин ҷо барои мо чизе нест, ки мо ба он бирасем.

& Иловаи забон Number Theory