Leandro Junes

Euler Totient

Compute how many integers from 1 to n are relatively prime to n.

Inputs

A positive integer, arbitrarily large.

Factorization difficulty depends on the size of the factors, not just the size of the input. The calculator may return a partial factorization for difficult inputs. Computation runs locally in your browser.

Try

Result

—

Prime factorization

—

How it works

For a prime power, the integers from 1 to p^a not coprime to p^a are exactly the multiples of p, of which there are p^(a−1). So

φ(p^a) = p^a − p^(a−1) = p^(a−1)(p − 1).

φ is multiplicative: φ(mn) = φ(m)φ(n) when gcd(m, n) = 1. Hence for n = p₁^a₁ ⋯ p_r^a_r,

φ(n) = ∏ p_i^(a_i−1)(p_i − 1) = n ∏(1 − 1/p_i).

The calculator uses only integer arithmetic. By convention φ(1) = 1.