Möbius Function and Mertens Function Calculator

Calculate μ(n) and M(n), test whether n is square-free, and inspect the exact summatory sequence. Inputs stay in your browser.

Enter a positive integer

Digits may include commas, spaces, or underscores as grouping separators. Decimals, zero, and negative integers are not accepted.

Results and working

Your results will appear here.

Try 30 to see μ(30) = −1 because 30 is the product of three distinct primes, and M(30) = −3.

Advertisement

What are the Möbius and Mertens functions?

The Möbius function μ(n) records whether a positive integer is square-free and the parity of its number of distinct prime factors. If n = p1p2⋯pk is square-free, then μ(n) = (−1)k. If any prime exponent is 2 or greater, μ(n) = 0. By definition, μ(1) = 1.

Möbius function: μ(n) = 1 if n = 1; μ(n) = (−1)k if n is a product of k distinct primes; μ(n) = 0 otherwise.

Mertens function: M(n) = ∑1 ≤ k ≤ n μ(k)

The Mertens function is the running total of Möbius values. Because terms with μ(k) = 0 do not change the sum, M(n) equals the number of square-free integers up to n with an even number of prime factors, including 1, minus the number with an odd number.

Worked examples

μ(1) and M(1)

The integer 1 has no prime factors. By definition, μ(1) = 1, so the first summatory value is M(1) = 1.

Square factor: μ(12)

12 = 22 × 3. Since the squared prime 22 divides 12, it is not square-free and μ(12) = 0.

Three distinct primes: μ(30)

30 = 2 × 3 × 5 is square-free with three distinct prime factors. Therefore μ(30) = (−1)3 = −1.

Two distinct primes: μ(35)

35 = 5 × 7 is square-free with two distinct prime factors. Therefore μ(35) = (−1)2 = 1.

First Möbius and Mertens values

nFactorizationμ(n)M(n)
1111
22−10
33−1−1
4220−1
55−1−2
62 × 31−1
77−1−2
8230−2
9320−2
102 × 51−1

Möbius and Mertens function FAQ

What values can the Möbius function have?

Only −1, 0, and 1. A zero identifies a number divisible by a prime square. For square-free numbers, an odd number of prime factors gives −1 and an even number gives 1.

What is the Mertens function?

M(n) is the summatory Möbius function: M(n) = μ(1) + μ(2) + ⋯ + μ(n). It is a running balance of positive and negative Möbius values.

What are μ(1) and M(1)?

By definition, μ(1) = 1. Since that is the only term in the first partial sum, M(1) = 1.

What does square-free mean?

A positive integer is square-free when no square greater than 1 divides it. In its prime factorization, every prime exponent must be 0 or 1.

How does this calculator compute M(n)?

It uses a linear sieve to generate every exact μ(k) from 1 through n, then forms cumulative integer sums. Typed arrays keep the work memory-efficient, and no floating-point approximations are used.

Why is the input limited to 2,000,000?

M(n) requires all Möbius values through n. The ceiling keeps CPU and memory use predictable on mobile devices while still supporting substantial explorations.

Is my input private?

Yes. The number and results remain in your browser. This calculator does not upload, save, or place the input in a URL.

Explore more tools