%mathpiper,def="Totient"

// Algorithm adapted from:
// Elementary Number Theory, David M. Burton
// Theorem 7.3 p139

10 # Totient(_n)	<--
[
	Check(IsPositiveInteger(n), "Argument", "Totient: argument must be positive integer");
	Local(i,sum,factors,len);
	sum:=n;
        factors:=Factors(n);
        len:=Length(factors);
        For(i:=1,i<=len,i++)[
		sum:=sum*(1-1/factors[i][1]);
        ];
	sum;
];

%/mathpiper