Liouville function calculator
λ(12) is −1, because 12 is 2 × 2 × 3, three prime factors counted with repetition. Enter any positive integer to get 1 for an even count or −1 for an odd one, with the count shown so you can check it. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 12
- Liouville
- -1
- Prime factors with multiplicity
- 3
The Liouville function calculator evaluates λ(n) for any supported positive integer by counting its prime factors with multiplicity. Every repeated prime counts again: for example, the three factors in 12 = 2 × 2 × 3 produce an odd count and therefore a result of −1. The calculator also reports that count, making the sign easy to inspect and verify. It is deterministic, requires no network access, and treats λ(1) as 1 because one has no prime factors.
What the Liouville function measures
The Liouville function is a compact arithmetic sign attached to every positive integer. Write n as a product of primes and let Ω(n) denote the number of factors in that product when repetition is retained. Then λ(n) = (−1)<sup>Ω(n)</sup>.
An even number of prime factors gives 1, while an odd number gives −1. Multiplicity is essential. The integer 18 factors as 2 × 3 × 3, so Ω(18) is three rather than two and λ(18) is −1.
By contrast, 12 × 3 = 36 factors as 2 × 2 × 3 × 3, giving four factors and a value of 1.
How to calculate λ(n)
Enter one integer n greater than or equal to 1. The calculator repeatedly divides out 2, then tests odd candidate divisors in increasing order. Every successful division increments the multiplicity count, including repeated divisions by the same prime.
Once the remaining quotient has no possible divisor at or below its square root, any quotient larger than one is itself a final prime factor and contributes one more to the count. Inputs below one are rejected because the capability is defined here only for positive integers. Fractions, nonnumeric values, and integers above the published input bound are also rejected instead of being rounded or silently approximated.
The implementation uses exact integer arithmetic within its supported range and has no random choices, clock-dependent behavior, external service calls, or stored state, so identical valid inputs always return identical results.
Using the result in number theory
Liouville values are useful whenever the parity of total prime multiplicity matters. Because Ω(ab) = Ω(a) + Ω(b), the function is completely multiplicative: λ(ab) = λ(a)λ(b), even when a and b share prime factors. That property makes the output convenient for checking hand calculations, building arithmetic-function tables, testing identities, and preparing examples involving Dirichlet series or summatory functions.
A sequence experiment can call the capability once for each positive integer and accumulate the returned signs to study partial sums, while a teaching tool can display the reported factor count beside the sign to emphasize why repeated primes matter.
What you can do with it
Check a factorization exercise
Confirm whether the total prime-factor multiplicity is even or odd and compare the reported count with your work.
Build an arithmetic-function table
Evaluate successive positive integers and store a deterministic λ(n) value for each row.
Test multiplicative identities
Compare λ(ab) with λ(a)λ(b) while developing or teaching completely multiplicative functions.
FAQ
What is the Liouville function?
It is λ(n) = (−1) raised to Ω(n), where Ω(n) counts prime factors with multiplicity.
What is λ(1)?
It is 1. The integer 1 has zero prime factors, and zero is even.
Do repeated prime factors count more than once?
Yes. In 12 = 2 × 2 × 3, both copies of 2 count, so Ω(12) is three.
Why are values below one rejected?
This capability accepts the standard positive-integer domain only, so n must be at least 1.
Is the Liouville function multiplicative?
Yes, completely. The value for a product equals the product of the values, even when the two numbers share prime factors, because the factor counts simply add. For example, 12 gives −1 and 3 gives −1, so 36 gives 1.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/numth/liouville-function \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":12}'const res = await fetch("https://api.kit.forhosting.com/numth/liouville-function", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 12
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/liouville-function",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 12
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/liouville-function", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":12}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":12}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/liouville-function", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 12
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.liouville_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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
min_n | 1 |
max_n | 1000000000000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
What the Liouville function measures
For n = 1, the prime factorization is empty, Ω(1) is zero, and the result is 1. This calculator returns both the sign and the counted multiplicity so that the result is transparent. It does not confuse Ω(n) with the number of distinct primes, commonly written ω(n), which would produce the wrong answer whenever a prime repeats an even number of additional times.
How to calculate λ(n)
The output field prime_factors_with_multiplicity is Ω(n), and liouville is 1 when that count is even or −1 when it is odd.
Using the result in number theory
API requests cost $0.002 each, while the browser execution uses the same pure calculation. This capability evaluates one n per request; clients that need a range should iterate explicitly and preserve each corresponding input with its result.
Technical questions
How much does an API request cost?
Each API request costs $0.002. The same deterministic calculation can also run in the browser.