The Möbius function is a tool from number theory that answers a surprisingly simple question: given a positive integer, how many distinct prime factors does it have, and are any of those factors repeated? It assigns each integer a value of −1, 0, or 1 based on the answer.
Think of it as a "prime factor signature" that cares only about two things: whether the number is square-free (no prime squared divides it), and if so, whether the number of distinct primes is odd or even.
The Intuition First
Take any positive integer n. Factor it completely into primes:
n=p1a1p2a2⋯pkak
Now ask two yes/no questions:
Is any exponent ai≥2? That is, does any prime appear more than once in the factorization? If yes, the number is not square-free.
If the number is square-free, is the count k of distinct primes odd or even?
The Möbius function μ(n) encodes the answers:
If any prime repeats (ai≥2 for some i), then μ(n)=0.
If all primes appear exactly once (ai=1 for all i), then μ(n)=(−1)k, where k is the number of distinct primes.
So μ(n)=1 when n is square-free with an even number of prime factors, and μ(n)=−1 when n is square-free with an odd number of prime factors.
The Special Case: n=1
The number 1 has no prime factors at all. It is square-free by convention, and the number of distinct primes is k=0. Since (−1)0=1, we define:
μ(1)=1
This is not arbitrary — it makes the Möbius function work beautifully in sums and inversions, as you will see later.
The Precise Definition
μ(n)=⎩⎨⎧10(−1)kif n=1,if n is not square-free (some prime squared divides n),if n is square-free with exactly k distinct prime factors.
The Möbius function μ(n) is 0 whenever n has a repeated prime factor, and (−1)k when n is square-free with k distinct prime factors, so both 12 and 35 must first be factorised. …