EulerPhi[n]
gives the Euler totient function
.
EulerPhi
EulerPhi[n]
gives the Euler totient function
.
Details
- EulerPhi is also known as the Euler totient function or phi function.
- Integer mathematical function, suitable for both symbolic and numerical manipulation.
- Typically used in cryptography and in many applications in elementary number theory.
- EulerPhi[n] counts positive integers up to n that are relatively prime to n.
- For a number
with
a unit and
primes, EulerPhi[n] gives
.
Examples
open all close allBasic Examples (2)
Scope (9)
Numerical Evaluation (4)
EulerPhi[10]EulerPhi[-10]EulerPhi[50!]EulerPhi threads over lists:
EulerPhi[{2, 4, 6}]TraditionalForm formatting:
EulerPhi[n]//TraditionalFormSymbolic Manipulation: (5)
Solve equations involving EulerPhi:
FindInstance[EulerPhi[m]EulerPhi[n] == EulerPhi[m n] && 0 < m < n < 10, {n, m}, Integers, 3]Solve[EulerPhi[m] == 10, m, Integers]Use FullSimplify with EulerPhi:
FullSimplify[EulerPhi[n] >= Sqrt[n], n∈Integers && n > 6]FullSimplify[DivisorSigma[0, n] < EulerPhi[n], n∈Integers && n > 30]Use FunctionExpand with EulerPhi:
FunctionExpand[EulerPhi[p], p∈Primes]FindSequenceFunction can recognize the EulerPhi sequence:
Table[EulerPhi[n], {n, 10}]FindSequenceFunction[%, n]DirichletTransform[EulerPhi[n], n, s]Applications (9)
Basic Applications (4)
Cases[Range[100], n_ /; EulerPhi[CarmichaelLambda[n]] == CarmichaelLambda[EulerPhi[n]]]Length of the nth-order FareySequence can be expressed in terms of EulerPhi:
Table[Length[FareySequence[n]], {n, 15}]Table[1 + Sum[EulerPhi[n], {n, k}], {k, 1, 15}]Power series of the generating function for GCD:
Series[Total[EulerPhi[#]x ^ # / (1 - x ^ #)& /@ Divisors[10]], {x, 0, 20}]Sum[GCD[k, 10]x ^ k, {k, 1, 20}]Count the number of primes using EulerPhi:
Plot[{Underoverscript[∑, n = 2, Floor[x]]Floor[(EulerPhi[n]/n - 1)], PrimePi[x]}, {x, 0, 50}, PlotStyle -> {Thick, Directive[Yellow, Thick, Dashed]}]Number Theory (5)
Model Fleck's totient function:
FleckPhi[k_, n_] := Times@@(Sum[(-1)^jBinomial[k, j]EulerPhi[#1^#2 - j], {j, 0, #2}]&@@@FactorInteger[n])Table[FleckPhi[0, n], {n, 12}]
reproduces the Euler totient function:
Table[EulerPhi[n], {n, 12}]Generalizations and closed forms:
Table[FleckPhi[-1, n] - n, {n, 12}]Table[FleckPhi[-2, n] - DivisorSigma[1, n], {n, 12}]Plot the cumulative sum of EulerPhi:
ListPlot[Accumulate[Table[EulerPhi[n], {n, 50}]]]Compare with an asymptotic approximation:
Show[%, Plot[3 / Pi ^ 2n ^ 2, {n, 0, 50}, PlotStyle -> Red]]First several
-s where the difference
is negative:
Position[NonPositive[Accumulate[EulerPhi[Range[10 ^ 4]]] - 3(Range[10 ^ 4] / Pi) ^ 2], True]//FlattenTable[Sum[EulerPhi[n], {n, 1, k}] - 3k ^ 2 / Pi ^ 2, {k, %}]//NThe probability that two randomly chosen positive integers less than x are relatively prime:
ListLinePlot[Table[(1/x^2)(-1 + 2Underoverscript[∑, n = 1, ⌊x⌋]EulerPhi[n]), {x, 1, 100}]]Compare with the asymptotic limit:
N[1 / Zeta[2]]Build RSA-like encryption scheme. Start with the modulus:
{p, q} = Prime[RandomInteger[{10 ^ 4, 10 ^ 5}, {2}]];
n = p qFind the universal exponent of the multiplication group modulo n:
ϕ = EulerPhi[n]d = NestWhile[#1 + 1&, Round[n / 3], GCD[ϕ, #1] =!= 1&]e = PowerMod[d, -1, ϕ]PowerMod[ToCharacterCode["RSA in Mathematica"], e, n]FromCharacterCode[PowerMod[%, d, n]]Number of cyclic necklaces of length n that can be formed with b types of beads:
c[n_, b_] := Total[EulerPhi[#]b^(n/#)&[Divisors[n]]] / nc[6, 2]Properties & Relations (11)
EulerPhi is non-negative:
EulerPhi[0]EulerPhi is a multiplicative function:
m = 12;
n = 8;
EulerPhi[m]EulerPhi[n] == EulerPhi[m n](EulerPhi[GCD[n, m]]/GCD[n, m])For any prime number p and natural number r, ϕ(pr)=pr-pr-1:
Assuming[p∈Primes && r∈Integers && r > 0, FunctionExpand[EulerPhi[p ^ r]]]Similarly, EulerPhi[n]==n∏p|n(1-1/p) where p is prime:
100Product[1 - 1 / k, {k, Select[Divisors[100], PrimeQ]}]EulerPhi[100]Alternatively, EulerPhi[n]==n∑k|nMoebiusMu[k]/k:
35Sum[MoebiusMu[k] / k, {k, Divisors[35]}]EulerPhi[35]CarmichaelLambda divides EulerPhi:
Divisible[EulerPhi[8], CarmichaelLambda[8]]When n is a prime power, they are equal:
PrimePowerQ[25]{EulerPhi[25], CarmichaelLambda[25]}DivisorSum[15, EulerPhi] == 15For a Cyclotomic field, the NumberFieldDiscriminant can be found using EulerPhi:
n = 7;NumberFieldDiscriminant[x /. Solve[Cyclotomic[n, x] == 0][[1]]]
((-1) ^ (EulerPhi[n] / 2)n ^ EulerPhi[n]) / Product[p ^ (EulerPhi[n] / (p - 1)),
{p, Divisors[n][[2 ;; All]]}]If
has a primitive root, then CarmichaelLambda and EulerPhi are the same:
Cases[Range[2, 20], n_ /; IntegerQ[PrimitiveRoot[n]]]CarmichaelLambda[%]EulerPhi[%%]Determine EulerPhi through prime factorization:
ϕ[n_] := n Times@@(1 - (1/First /@ FactorInteger[n]))Table[ϕ[n], {n, 12}]Table[EulerPhi[n], {n, 12}]For any square-free number n, the totient of n is equal to the product of the totients of each factor of n :
SquareFreeQ[1023]FactorInteger[1023]EulerPhi[1023] == EulerPhi[3] * EulerPhi[11] * EulerPhi[31]Neat Examples (4)
Form an absolutely abnormal number as the limit of the following sequence:
d[j_] := If[j == 2, 2, j ^ EulerPhi[d[j - 1]]]
α[k_] := Product[1 - 1 / d[j], {j, 2, k}]Table[α[k], {k, 5}]Digits of the sixth approximation in various bases:
Table[BaseForm[N[α[6], 50], b], {b, 2, 24}]//TableFormIterate the map
and display result modulo
:
With[{a = 1.537, b = -.5, m = 3}, ArrayPlot[Mod[FixedPointList[EulerPhi[Floor[a# + b]]&, Range[150], 100], m]]]Cases[Range[100], n_ /; PrimePi[n] == EulerPhi[n]]DiscretePlot[{PrimePi[n], EulerPhi[n]}, {n, 1, 22}, Epilog -> {Red, PointSize[0.03], Point[{#, EulerPhi[#]}& /@ %]}]Plot of Ulam spiral where numbers are colored based on the values of EulerPhi:
ulam[n_] := Partition[Permute[Range[n ^ 2], Accumulate[Take[Flatten[{{n ^ 2 + 1} / 2,
Table[(-1) ^ j i, {j, n}, {i, {-1, n}}, {j}]}], n ^ 2]]], n]
ArrayPlot[EulerPhi[ulam[141]], ColorFunction -> Hue]See Also
MultiplicativeOrder CarmichaelLambda PowerMod CoprimeQ FactorInteger GCD LCM Divisors PrimeQ SquareFreeQ PrimePowerQ MoebiusMu
Function Repository: JordanTotient RamanujanC Totatives
Tech Notes
History
Introduced in 1988 (1.0) | Updated in 2007 (6.0)
Text
Wolfram Research (1988), EulerPhi, Wolfram Language function, https://reference.wolfram.com/language/ref/EulerPhi.html (updated 2007).
CMS
Wolfram Language. 1988. "EulerPhi." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/EulerPhi.html.
APA
Wolfram Language. (1988). EulerPhi. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/EulerPhi.html
BibTeX
@misc{reference.wolfram_2026_eulerphi, author="Wolfram Research", title="{EulerPhi}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/EulerPhi.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_eulerphi, organization={Wolfram Research}, title={EulerPhi}, year={2007}, url={https://reference.wolfram.com/language/ref/EulerPhi.html}, note=[Accessed: 13-June-2026]}