August 23, 2024
P34 - Calculate Euler's totient function phi(m).
Euler's so-called totient function phi(m) is defined as the number of positive integers r (1 <= r <= m) that are coprime to m.
> p34:totient(10).
4
erlang
%Determine whether two positive integer numbers are coprime.
-module(p34).
-export([totient/1]).
totient(A) ->
length(lists:filter(fun(B) -> p33:coprime(A, B) end ,lists:seq(1, A))).