How this calculation works
Multiplying by a prime flips the sign, even if that prime already appears in the factorization.
λ(n) = (−1)^Ω(n)A worked example
12 = 2 × 2 × 3 has three prime factors with multiplicity, giving −1.
Good to know
The empty factorization of 1 gives +1.
Reference: NIST DLMF, Functions of Number Theory (opens in a new tab) ↗
Count prime factors with repetition
Write 12 as 2 × 2 × 3. Counting every prime factor gives Ω(12) = 3. The Liouville value is λ(12) = (−1)³ = −1. By contrast, 18 = 2 × 3 × 3 also has three factors and the same value, even though its prime exponents differ.
For 36 = 2² × 3², the exponent sum is 2 + 2 = 4, an even number, so λ(36) = 1. The output depends on parity of the total exponent count. It does not require multiplying the full expanded factor list once the exponents are known.
Use multiplication to check the sign
The Liouville function is completely multiplicative. Prime exponents add when integers multiply, so λ(ab) = λ(a)λ(b), including when a and b share a prime factor. For example, λ(6) = 1 and λ(2) = −1, giving λ(12) = −1.
The Möbius function calculator additionally tests for prime squares and can return zero. Liouville never returns zero for an accepted positive input. A perfect square has even prime exponents, so its exponent total is even and its Liouville value is 1. The value for 1 is also 1 because its factorization has zero prime factors and (−1)⁰ = 1.
Read more: NIST DLMF definition of the Liouville function (opens in a new tab) ↗
A few questions, answered
Do I count two distinct primes in 12?
It has two distinct primes but three prime factors with multiplicity. Liouville uses the latter count.
Can different integers share the same output?
Yes. Only the parity of the exponent total is retained, so many integers map to each of the two possible values.