Möbius Function & Möbius Inversion

Linear sieve of μ(n), and coprime-pair counting via Σ μ(d)·⌊n/d⌋²

Sieve μ(1..n): O(n) Single μ(n): O(√n) Coprime count: O(n) / O(√n) blocked Identity: μ * 1 = ε

Linear Sieve of the Möbius Function

μ = +1 (even #primes) μ = −1 (odd #primes) μ = 0 (not squarefree) current

Step Explanation

Press Play to run the linear sieve, or Step to advance one operation.

Operation Log

Ready.

Live Facts

step0 / 0
modesieve
n12
running total
cross-check

Complexity

OperationTime
μ(n), one value (factor)O(√n)
μ(1..n) linear sieveO(n)
μ(1..n) EratosthenesO(n log log n)
Inversion at one nO(d(n))
Coprime count Σμ(d)⌊n/d⌋²O(n)
Coprime count (divisor blocks)O(√n)
Sublinear Mertens M(x)O(n^2/3)

Formula

Sieve: μ(i·p) = 0 if p|i, else −μ(i)
Coprime pairs ≤ n:
Σd=1..n μ(d)·⌊n/d⌋²