Google Classroom
GeoGebraGeoGebra Classroom

Euler's totient function

Euler's totient function counts the positive integers up to a given integer n that are relatively prime to n. Note: It works for n < 1014-1
This version uses only GGb scripting, but here is another version with JavaScript: https://www.geogebra.org/m/sg2njyd5

Script I

n = 123456 Inp = InputBox(n) SetCaption(Inp, "n = ") facts = Factors(n) phi = If(n <=0 , ?, If( n == 1, 1, Product(Sequence(Element(facts, i, 1)^(Element(facts, i, 2) - 1) (Element(facts, i, 1) - 1), i, 1, Length(facts))) ) text = "\phi(n) = " + phi

Script II

n = 123456 Inp = InputBox(n) SetCaption(Inp, "n = ") F = Unique(PrimeFactors(n)) phi = If(n<=0, ?, If(n == 1, 1, n Product(Zip(1 - 1 / p, p, F)))) text = "\phi(n) = " + phi
Script improved with the help of Thijs.