Factorial prime factorization
10! factors as 2⁸ × 3⁴ × 5² × 7, and you get that list without ever computing the full product. Enter n from 0 to 100000 and see every prime up to n with its exponent, worked out with Legendre's formula. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
The prime factorization of n factorial is a classic number-theory result: every prime at most n appears in n!, and its exact power is given by Legendre's formula without ever writing out the huge product 1×2×…×n. Students, contest programmers, and cryptography learners all need those exponents for binomial coefficients, p-adic valuations, and factorial-divisibility checks.
What Legendre's formula computes and why it beats expanding n!
For a non-negative integer n, n! is the product of all positive integers up to n (with the conventions 0! = 1! = 1). Writing that product in full is impractical once n reaches a few dozen, because the decimal value of n!
grows faster than any fixed-width integer type can hold. Yet the prime factorization of n! is completely determined by a short closed form: if p is a prime and p ≤ n, the exponent of p in n!
equals the infinite-looking but finite sum floor(n/p) + floor(n/p²) + floor(n/p³) + …, stopping as soon as p^k exceeds n. That identity is Legendre's formula (also called de Polignac's formula). It counts how many multiples of p, of p², of p³, and so on contribute factors of p when you expand the product 1·2·…·n.
= 2^8 × 3^4 × 5^2 × 7. No randomness, no sampling, and no multiprecision factorial is required—only integer division and a list of primes.
Where factorial factorizations show up in practice
p-adic valuations of factorials appear whenever you simplify binomial coefficients, compute the highest power of a prime dividing a multinomial, or prove that a factorial is divisible by a given integer. Competitive programming problems often ask for the exponent of p in n! or for the full factorization of n!
under a modest n bound; Legendre's formula is the standard answer key. In teaching, showing students that 25! is divisible by 5 exactly floor(25/5)+floor(25/25) = 5+1 = 6 times makes the counting argument concrete without a wall of multiplications.
Cryptography and number-theory notebooks sometimes need the prime signature of n! as a building block for examples about smooth numbers or primorials.
What you can do with it
Check p-adic valuations in homework and contests
Students and contestants can verify the exponent of each prime in n! before submitting proofs or programming solutions that depend on Legendre's formula.
Build smooth-number and factorial demos
Teaching notebooks and recreational number-theory tools can display the prime signature of n! without expanding the full factorial value.
FAQ
What is the prime factorization of n factorial?
It is the product of primes p ≤ n each raised to the power given by Legendre's formula: floor(n/p) + floor(n/p²) + … until the power exceeds n.
How does this calculator avoid computing n! directly?
It lists primes up to n with a sieve, then applies Legendre's sum for each prime. The huge decimal value of n! is never constructed.
What happens if n is negative?
Factorial is only defined here for non-negative integers within the published range.
Is the factorial prime factorization tool free?
The browser tool is free and runs locally.
What do 0! and 1! return?
Both equal 1, so the response factors array is empty—there are no prime factors to list.
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/factorial-prime-factors \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":10}'const res = await fetch("https://api.kit.forhosting.com/numth/factorial-prime-factors", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 10
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/factorial-prime-factors",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 10
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/factorial-prime-factors", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":10}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":10}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/factorial-prime-factors", 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": 10
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.factorial_prime_factors",
"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
max_n | 100000 |
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
This capability sieves the primes up to n, sums floor(n/p) + floor(n/p²) + … for each prime, and returns an ordered list of prime/exponent pairs—deterministic, offline, and free to try in your browser before you wire the API path into homework pipelines or automated checkers.
What Legendre's formula computes and why it beats expanding n!
For example, with n = 10 the primes at most 10 are 2, 3, 5, and 7; the exponent of 2 is floor(10/2)+floor(10/4)+floor(10/8) = 5+2+1 = 8, the exponent of 3 is 3+1 = 4, of 5 is 2, and of 7 is 1, so 10!
How to call the API and what the response contains
For n equal to 0 or 1 the factor list is empty because both factorials equal 1 and 1 has no prime factors. Use it from contest solvers, classroom demos, binomial-coefficient valuation scripts, or any workflow that needs a reproducible factorization of n! without installing a computer-algebra system. Send a JSON body with a single required field n—a whole number at least 0 and at most one hundred thousand (100000). Aliases number and value are accepted for the same field so browser forms and scripts can share one contract. On success the response echoes n as accepted and returns factors as an ascending list of objects each with prime and exponent. Validation failures—missing n, a non-integer, a fractional value, a negative n, or a value above the published maximum—return invalid_input and are never charged. Pricing is a flat $0.002 per successful request (unit item with zero marginal unit price).
Where factorial factorizations show up in practice
Keep n within the published limit so the sieve and the Legendre loops stay interactive on the edge Worker; for enormous n you would need a specialized multiprecision stack, not this lightweight parse capability. Negative inputs are rejected because the real factorial is not defined for negative integers in this API contract.
Integration use cases
Simplify binomial coefficients from factorizations
Scripts that cancel primes in C(n,k) can pull the factorization of n!, k!, and (n−k)! from this endpoint and subtract exponents deterministically.