Euler's totient function

[b]Euler's totient function[/b] counts the positive integers up to a given integer [i]n[/i] that are relatively prime to [i]n[/i].[br][br][b]Note:[/b] It works for n < 10[sup]15[/sup]-1
This example uses JavaScript but it seems to be easier using just GGB script:[br][br]https://www.geogebra.org/m/mvxnxamm
1. Global JavaScript
function ggbOnInit() {}[br][br]// Euler's Totient Function[br]// https://en.wikipedia.org/wiki/Euler%27s_totient_function[br]// using Euler's product formula[br]function phi(n) {[br] // Initialize[br] // result as n[br] var result = n;[br][br] // Consider all prime[br] // factors of n and subtract[br] // their multiples from result[br] for (var p = 2; p * p <= n; ++p) {[br][br] // Check if p is[br] // a prime factor.[br] if (n % p == 0) {[br][br] // If yes, then[br] // update n and result[br] while (n % p == 0)[br] n = parseInt(n / p);[br] result -= parseInt(result / p);[br][br] }[br] }[br][br] // If n has a prime factor[br] // greater than sqrt(n)[br] // (There can be at-most[br] // one such prime factor)[br] if (n > 1)[br] result -= parseInt(result / n);[br] return result;[br]}[br][br]// This code is contributed[br]// by _saurabh_jaiswal
2. Basic Setup
n = 123456[br][br]phi = ?[br][br]Inp = InputBox(n)[br]SetCaption(Inp, "n = ")[br][br]text = "\phi(n) =" + phi
3. Create button named "Calculate" with JavaScript
var n = ggbApplet.getValue('n');[br][br]if ( n <= 0 )[br] ggbAppletevalCommand("SetValue(phi, ?)");[br]else if ( n === 1)[br]ggbApplet.setValue("phi", 1);[br]else ggbApplet.setValue("phi", phi(n));
4. Finally, add script in "n" on Update tab
RunClickScript( Calculate )

Informatie: Euler's totient function