Möbius Function Calculator

Input

Mobius function mu(n)-1
Factorization2 x 3 x 5
Distinct prime factors3
SquarefreeYes
How this was calculated
  1. Factor 30 into primes: 2 x 3 x 5.
  2. The number has 3 distinct prime factors, and none of them is squared.
  3. The Möbius function is zero whenever a squared prime divides n; otherwise it is +1 or -1 by the parity of the prime factor count.
  4. So mu(30) = -1: the value is -1, because n is squarefree with an odd number of prime factors.

This Möbius function calculator finds mu(n) for any whole number you enter. The Möbius function mu(n) is 0 if any prime squared divides n, +1 if n is a product of an even number of distinct primes, and -1 for an odd number. The calculator factors your number into primes, checks whether any prime appears more than once, and counts the distinct primes that remain. That count decides the sign of the answer. For example, 30 = 2 x 3 x 5 has three distinct prime factors and no squared factor, so mu(30) = -1. And 12 = 2^2 x 3 is divisible by the squared prime 4, so mu(12) = 0. By convention mu(1) = 1, treating 1 as a product of zero primes.

The calculator relies on the definition of the Möbius function itself: the answer follows directly from the prime factorization of n, so the result is exact rather than estimated. Each case is handled by the same rule — a repeated prime gives 0, an even number of distinct primes gives +1, and an odd number gives -1. This page shows the formula, the step-by-step workings, worked examples such as 210 = 2 x 3 x 5 x 7, which has four distinct prime factors and therefore mu(210) = 1, and the sources behind the method. You can follow every step from the input number to the final value.

Worked examples

Three distinct primes

(30)

Mobius function mu(n)-1
Factorization2 x 3 x 5
Distinct prime factors3
SquarefreeYes

Squared prime factor

(12)

Mobius function mu(n)0
Factorization2^2 x 3
Distinct prime factors2
SquarefreeNo

Four distinct primes

(210)

Mobius function mu(n)1
Factorization2 x 3 x 5 x 7
Distinct prime factors4
SquarefreeYes

Three answers and what decides them

The Möbius function mu(n) gives one of three answers, and the definition tells you exactly which. It is 0 if any prime squared divides n, +1 if n is a product of an even number of distinct primes, and -1 for an odd number. A mobius function calculator applies this rule for you, but the rule itself is simple enough to follow by hand, and the worked examples below show how. The method is always the same: factorize first, look for a squared prime, then count the distinct primes and take the parity.

Start with 12. Factorizing gives 12 = 2^2 x 3. The squared prime 4 divides 12, so the first condition is triggered and mu(12) = 0. Once a squared prime appears in the factorization, the count of distinct primes no longer matters, because the answer is already settled as 0.

Now take 30. Factorizing gives 30 = 2 x 3 x 5. There is no squared factor, so the answer is not 0. The distinct primes are 2, 3 and 5, which is three of them. Three is an odd number, so mu(30) = -1. Notice that the exponents are all 1, which is what lets the count of distinct primes decide the sign.

Next, 210. Factorizing gives 210 = 2 x 3 x 5 x 7. Again there is no squared factor. The distinct primes are 2, 3, 5 and 7, which is four of them. Four is even, so mu(210) = 1. Comparing 30 and 210 shows the only difference: three distinct primes gave -1 and four distinct primes gave +1, so the parity of the count flips the sign.

One special case sits outside the factorization steps. By convention mu(1) = 1, treating 1 as a product of zero primes. Zero is even, so this matches the parity rule rather than contradicting it.

The order of the checks matters less than it seems, because a squared prime always forces 0 regardless of how many distinct primes there are. What matters is that you factorize completely before counting. If you count primes from an incomplete factorization, you can miss a squared prime or miscount the distinct ones, and the sign or the zero will come out wrong.

  • 12 = 2^2 x 3: the squared prime 4 divides 12, so mu(12) = 0.
  • 30 = 2 x 3 x 5: three distinct primes, no squared factor, so mu(30) = -1.
  • 210 = 2 x 3 x 5 x 7: four distinct primes, no squared factor, so mu(210) = 1.
  • 1: treated as a product of zero primes, so mu(1) = 1 by convention.
Factorize fully, check for a squared prime first, then count the distinct primes: odd gives -1, even gives +1.

Where mu shows up

The Möbius function is more than a curiosity about prime factors. It is the tool behind a family of identities that let you convert a sum over divisors into a sum over the integers themselves, and back again. That flexibility is why a Möbius function calculator earns its place in number theory work: once you can compute mu(n) quickly, several classic counting problems become bookkeeping exercises.

The central identity is the Möbius inversion formula. It says that if a function f is built by summing another function g over the divisors of n, then g can be recovered by weighting those divisor sums with mu. In practice this means a quantity that is hard to count directly — because it depends on divisibility structure — can be expressed as a combination of easier quantities, with mu supplying the plus and minus signs. The sign pattern is exactly what mu encodes: 0 when a squared prime divides n, +1 when n is a product of an even number of distinct primes, and -1 when that number of distinct primes is odd.

Two counting problems lean on this directly. Counting squarefree numbers up to a bound is naturally phrased with mu, since mu(n) is zero precisely when n fails to be squarefree. Counting coprime pairs is similar: the condition that two integers share no common prime factor can be tested by summing mu over common divisors, and inversion turns that into a usable formula. The same reasoning underlies many sieve-based estimates, where mu acts as a weight that cancels unwanted terms.

A related object is the Mertens function, defined as the running sum of mu values up to a point. Because mu takes the values 0, +1 and -1, the Mertens function is a running tally of how the plus and minus signs have balanced so far, and it is often studied as a compact summary of the behavior of mu over a range. Computing it is straightforward once individual values are known: add each mu(n) in turn.

Checking individual values by hand is a good way to build intuition before trusting any table. The examples below follow directly from the definition.

nFactorizationDistinct primesmu(n)
1empty product (convention)01
122^2 x 320
302 x 3 x 53-1
2102 x 3 x 5 x 741
Remember the convention mu(1) = 1: 1 is treated as a product of zero primes, and zero is an even number.

Squarefree numbers

The Möbius function is zero on exactly one kind of number: the non-squarefree ones. A number is squarefree when no prime squared divides it. So mu(n) is nonzero precisely when n is squarefree, and it is zero whenever some prime squared divides n. This single rule explains most of the zeros a mobius function calculator will show you, and it is worth seeing how the rule plays out on real numbers.

Take 12 = 2^2 x 3. Because 4 divides 12, the squared prime 2 is present, and mu(12) = 0. The zero does not depend on how many other primes are in the factorization: one repeated prime is enough. Now compare 30 = 2 x 3 x 5. It has three distinct prime factors and no squared factor, so it is squarefree and mu(30) = -1, the sign for an odd count of distinct primes. And 210 = 2 x 3 x 5 x 7 has four distinct prime factors, so mu(210) = 1, the sign for an even count. In each case the question is the same: does any prime appear twice in the factorization? If yes, the answer is 0.

By convention mu(1) = 1, treating 1 as a product of zero primes. Zero is an even number, so this fits the sign rule: an even number of distinct primes gives +1. The squarefree numbers therefore begin 1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, and so on, while 4, 8, 9, 12, 16, 18, 20 and their relatives are excluded because a square divides them.

In the long run, about 6 in 10 integers are squarefree, so a list of mu values settles at roughly 60 percent nonzero entries and 40 percent zeros. That proportion is a long-run average, not a rule for any short stretch: small runs can look quite different, and the balance smooths out only as you count more integers. The zeros are not scattered at random either. They cluster wherever multiples of 4, 9, 25 and other prime squares appear, which is why stretches containing many such multiples show more zeros than the average suggests.

When you check a value by hand or with a mobius function calculator, factor the number first and look for any repeated prime. If you find one, the answer is 0 and you can stop. If every prime appears exactly once, count them: an odd count gives -1, an even count gives +1, and the special case 1 gives +1 by convention.

mu(n) is nonzero exactly when n is squarefree. One squared prime factor, as in 12 = 2^2 x 3, forces mu(12) = 0.

Computing mu by hand and by sieve

To compute the Möbius function for a single value by hand, factor the number into primes and then apply the definition. If any prime squared divides the number, mu(n) is 0. Otherwise, count how many distinct primes appear: an even count gives +1, an odd count gives -1. The special case mu(1) = 1 follows the convention that 1 is a product of zero primes, and zero is even, so the sign is positive. A mobius function calculator automates exactly this check, but walking through a few examples makes the rule concrete.

Start with 30. Its prime factorization is 2 x 3 x 5, so there are three distinct primes and no repeated factor. Three is odd, so mu(30) = -1. Now take 12: it factors as 2^2 x 3, which contains the squared prime 4. Because a square divides 12, mu(12) = 0 regardless of how many other primes appear. Finally, 210 = 2 x 3 x 5 x 7 has four distinct prime factors and no squared factor. Four is even, so mu(210) = 1. These three cases cover all the outcomes the function can produce.

For a single number, trial division is the practical method. Divide out 2 as many times as possible, then test odd divisors up to the square root of what remains. If any prime divides twice, you can stop immediately and report 0. If every prime divides only once, tally the distinct primes and set the sign from the parity of that count. This is fast for one value, but repeating it for every integer in a long range becomes slow, which is where the sieve approach helps.

A sieve computes mu for every number up to a limit in one pass. Mark each prime, then for each prime p multiply mu values at multiples of p by -1 to account for one new distinct prime. Separately, set mu to 0 at every multiple of p^2, since those numbers are divisible by a squared prime. After processing all primes up to the limit, every entry holds its correct value, including mu(1) = 1 set at the start. The calculator accepts n up to 1,000,000, so a sieve over that range is well within reach and returns results for the whole interval at once.

  • mu(30) = -1: three distinct primes (2, 3, 5), odd count, no squared factor.
  • mu(12) = 0: divisible by the squared prime 4.
  • mu(210) = 1: four distinct primes (2, 3, 5, 7), even count.
  • mu(1) = 1 by convention, treating 1 as a product of zero primes.
Quick check: if any prime square divides n, the answer is 0. Otherwise the answer is +1 for an even number of distinct primes and -1 for an odd number. The calculator handles n up to 1,000,000.

FAQs

What is the Möbius function?

The Möbius function is an arithmetic function written mu(n). It equals 0 when a squared prime divides n. Otherwise it is +1 or -1, depending on whether the number of distinct prime factors is even or odd. So every input lands on one of those three values, never anything else.

Why is mu(12) equal to 0?

Because 12 = 2^2 x 3 contains the squared prime factor 2^2. Any squared prime factor forces mu to 0, no matter what the rest of the factorization looks like. So mu(12) is 0, not +1 or -1, since the squared prime 2^2 divides 12 evenly.

What is mu(1)?

It is 1, by convention. The number 1 has zero prime factors, and zero is an even count, so the sign is positive. The empty product is also treated as squarefree. Together those conventions give mu(1) = 1, which keeps the function consistent with its definition.

How is the Möbius function used?

It drives Möbius inversion, a technique that recovers a function from its divisor sums. It also counts squarefree and coprime structures throughout number theory. These two roles make it a standard tool in analytic and combinatorial number theory, where sums of mu(n) are studied for their cancellations.

Is mu(n) ever something other than -1, 0 or 1?

No. Those three values are the whole range of the Möbius function. Every n gives -1, 0 or 1 and nothing else. That tight range is exactly what makes its averages and cancellations so studied, since the values can only shift among three possibilities as n grows.

What is the largest n this calculator takes?

The largest n is 1,000,000. The calculator factors the input by trial division, which is instant for a single value at that size. So you can enter any n up to 1,000,000 and get the factorization and the resulting Möbius value right away, with no waiting.

Sources

Related calculators

Prime Factorization Calculator
Break any whole number up to a trillion into its prime factors — with divisor count, divisor sum and largest prime factor.
Prime Number Checker
Is it prime? The verdict, the full prime factorization, the smallest factor, the divisor count and the neighbouring primes on both sides.
Perfect Number Calculator
Classify a number as perfect, abundant or deficient by comparing it with the sum of its proper divisors (its aliquot sum).