Skip to content

Instantly share code, notes, and snippets.

@tomaslibal
tomaslibal / euler_phi.r
Last active January 25, 2021 15:38
A simple implementation of Euler's totient function ("Phi function"). More info about the function at http://mathworld.wolfram.com/TotientFunction.html. The language used here in this implementation is R (r-base-core 2.15.1-5ubuntu1).
# Eulers Totient Function
#
# Description at http://mathworld.wolfram.com/TotientFunction.html
# Algorithm based on http://en.wikipedia.org/wiki/Euler%27s_totient_function
# Interesting property: for a prime number p, epf(p) = p - 1
# greatest common divisor of two integers
# @param m int the first number
# @param n int the second number
# @return int the greates common divisor of the two numbers