Learn R Programming

pracma (version 1.1.6)

eulersPhi: Eulers's Phi Function

Description

Euler's Phi function (aka Euler's `totient' function).

Usage

eulersPhi(n)

Arguments

n
Positive integer.

Value

  • Natural number, the number of coprime integers <= n<="" code="">.

Details

The phi function is defined to be the number of positive integers less than or equal to n that are coprime to n, i.e. have no common factors other than 1.

See Also

factorize, sigma

Examples

Run this code
eulersPhi(9973)  == 9973 - 1                       # for prime numbers
eulersPhi(3^10)  == 3^9 * (3 - 1)                  # for prime powers
eulersPhi(12*35) == eulersPhi(12) * eulersPhi(35)  # TRUE if coprime

x <- 1:100; y <- sapply(x, eulersPhi)
plot(1:100, y, type="l", col="blue")
points(1:100, y, col="blue", pch=20)
grid()

Run the code above in your browser using DataLab