ForHosting KIT · Math

Mertens function calculator

Add up the Möbius function from 1 to n in one step: M(100) is 1, the exact signed balance between numbers with no repeated prime factor and an even or an odd count of prime factors. Works for any n up to 5,000,000. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
N
100
You get
Mertens
1

The Mertens function calculator returns M(n), the cumulative sum of the Möbius function from 1 through a positive integer n. It provides a direct way to inspect how square-free integers with even and odd numbers of distinct prime factors balance over an initial interval. Enter n and receive the exact integer result from a deterministic linear sieve. The calculation uses no random sampling, external service, or stored lookup table, so the same valid input always produces the same answer.

What the Mertens function measures

The Mertens function is defined by M(n) = μ(1) + μ(2) + ... + μ(n), where μ is the Möbius function. For a positive integer k, μ(k) is zero when a prime square divides k. Otherwise, μ(k) is 1 when k has an even number of distinct prime factors and -1 when it has an odd number.

The running sum therefore records a signed balance among square-free integers, while integers containing repeated prime factors make no contribution. In particular, μ(1) equals 1, so M(1) equals 1. The result can be positive, zero, or negative, and it should be read as an exact arithmetic value rather than a probability or approximation.

This cumulative quantity appears throughout analytic number theory because it connects multiplicative structure with questions about cancellation in arithmetic sequences.

How the calculator obtains an exact result

The implementation uses a linear sieve to construct Möbius values in increasing order. When the sieve encounters a prime, it assigns that prime a Möbius value of -1. For each previously discovered prime, it then considers the product with the current integer.

If that prime already divides the current integer, the product contains a squared prime factor, receives a Möbius value of zero, and processing for that integer stops. Otherwise, the product receives the negated Möbius value of the current integer. Each composite is handled through its smallest prime factor, which keeps the work proportional to the chosen upper bound.

As each new value is established, it is added to the running total. No floating-point formulas are involved, and no values are estimated. The algorithm is deterministic, operates locally, and returns an ordinary signed integer.

Input validation rejects fractions, non-finite numbers, values below one, and values beyond the published bound before allocating the sieve arrays.

Choosing inputs and interpreting the response

The response repeats the accepted n and supplies its Mertens value in the mertens field, which makes automated records self-describing. For example, a sequence of calls at increasing bounds can be used to plot the fluctuations of M(n), compare a textbook table with an independent calculation, or verify code that generates Möbius values by another method. Do not interpret a single positive or negative result as evidence of a lasting trend.

The function oscillates as contributions accumulate, and its theoretical interest concerns behavior across ranges and asymptotic bounds. If you need several values, retain each returned pair or compute at ascending checkpoints rather than assuming that M(n) reveals the individual value μ(n) without comparing it with M(n - 1).

Check a number theory exercise

Confirm an exact cumulative Möbius sum after deriving individual values by hand.

Validate a sieve implementation

Compare known checkpoints with results produced by another Möbius or prime-factor sieve.

Explore arithmetic cancellation

Collect M(n) at selected bounds to study its sign changes and fluctuations.

Is the result approximate?

No. A deterministic integer sieve computes every Möbius value used in the sum, so the returned result is exact.

What is the value of M(100)?

M(100) is 1. Adding the Möbius values of every whole number from 1 to 100 leaves a balance of one, so numbers with no repeated prime factor and an even count of prime factors are one ahead.

What does the Möbius function count?

It gives 0 to any number divisible by the square of a prime. Every other number gets 1 if it has an even number of distinct prime factors and −1 if it has an odd number. M(n) adds these values up.

Can the Mertens function be negative?

Yes. M(n) can be positive, zero or negative, depending on whether more numbers up to n with no repeated prime factor have an even or an odd count of prime factors. It is an exact whole number, never an estimate.

How large can n be?

Any whole number from 1 to 5,000,000. Fractions and values below 1 are refused. The sum always includes both ends, starting at 1 and finishing at the n you enter.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/mertens-function

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/mertens-function \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":100}'
{
  "n": 100
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.mertens_function",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_n5000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

What the Mertens function measures

This calculator includes both endpoints: an input of n asks for every Möbius value beginning at 1 and ending at n.

Choosing inputs and interpreting the response

Provide n as a JSON integer between 1 and 5,000,000 inclusive. A larger n requires more time and memory because the calculator must classify every integer through that endpoint; the declared ceiling keeps this cost bounded for both browser and API execution.

What is the Mertens function?

It is the running sum M(n) = Σ(k=1..n) μ(k), where μ is the Möbius function.

Does the sum include n?

Yes. The calculation includes every integer from 1 through n, including both endpoints.

What happens when n is below one?

The request fails with an invalid_input error because the Mertens function in this calculator requires a positive integer bound.

How much does an API calculation cost?

Each API request costs $0.002. The calculator also runs free in the browser.

Read the full KIT documentation →