Why it matters

Totient underlies RSA + many counting problems. Understanding shapes number theory.

Advertisement

The architecture

Factor n; apply formula.

Sieve: precompute phi for [1, N].

Euler totientFactor nprimesApply formulan * prod(1-1/p)Or use sievefor rangephi(p) = p - 1 for prime; phi is multiplicative for coprime factors
Totient computation.
Advertisement

How it works end to end

Multiplicative: phi(ab) = phi(a) phi(b) if gcd(a,b) = 1.

RSA: uses phi(pq) = (p-1)(q-1).

Fermat-Euler: a^phi(n) = 1 mod n.