Integer partition calculator
Count the ways to write a whole number as a sum when order does not matter: 4 splits into 4, 3+1, 2+2, 2+1+1 and 1+1+1+1, so p(4) is 5, and 5 has 7. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 5
- Value
- 7
- Quantity
- 7
- Power (W)
- 7
The integer partition function p(n) answers a classic counting question: in how many ways can you write a non-negative integer n as a sum of positive integers when the order of summands does not matter? For example, 4 equals 4, 3+1, 2+2, 2+1+1, and 1+1+1+1, so p(4) equals five; 5 has seven partitions and 10 has forty-two. Partitions appear in number theory, generating functions, statistical mechanics, and programming contests whenever you count multiset sums rather than ordered compositions or labeled set partitions. This capability accepts a non-negative integer n and returns the exact p(n) as a decimal string computed with BigInt dynamic programming, so values far beyond ordinary safe-integer limits stay correct digit for digit. Negative n is rejected with a clear validation error instead of a silent zero or a wrong answer.
How the partition function p(n) is defined
An unrestricted integer partition of a non-negative integer n is a way of writing n as a sum of positive integers in which the order of summands is irrelevant. By convention p(0) equals one, counting the empty partition of zero. Small textbook values are p(1)=1, p(2)=2 (namely 2 and 1+1), p(3)=3, p(4)=5, p(5)=7, p(6)=11, and p(10)=42.
The ordinary generating function for the sequence is the infinite product over k greater than or equal to one of one over one minus x to the k, which encodes that each positive integer may appear any number of times as a part. A practical recurrence used in software is the classic coin-change style dynamic program: initialize an array with one way to make sum zero, then for each part size from one through n, add the ways to form the remaining sum.
That recurrence fills p(n) exactly and never double-counts orderings because parts are introduced in non-decreasing size order only once. Related but different objects include compositions, where order matters and there are two to the n minus one compositions of n; set partitions counted by Stirling numbers of the second kind or Bell numbers, which partition labeled elements rather than add unlabeled positive integers; and restricted partitions that require distinct parts, odd parts only, or a fixed number of parts.
This implementation never uses floating-point approximation, Monte Carlo sampling, or external tables: it fills a one-dimensional BigInt array so every digit is correct. The path is fully deterministic—no random seeds, no clocks, no network, and no model drift—so the same n always yields the same string.
Where integer partitions show up in real work
Number-theory courses and programming contests constantly ask how many unrestricted partitions a given n has, how p(n) grows, or whether a table of small values matches the Ramanujan congruences and other classical identities. Algorithm designers use partition counts when analyzing integer knapsack style state spaces, counting multiset decompositions of a resource budget, or sizing DP tables whose dimensions track part sizes.
Physics and combinatorics contexts connect p(n) to bosonic partition functions and generating-function coefficients; educators often show a short list of partitions of a small n and then ask for the count alone. Interview prep and olympiad training frequently need a single reliable p(n) without hand-maintaining large tables or risking off-by-one composition counts.
If you later need compositions where order matters, set partitions via Stirling numbers of the second kind, Bell numbers alone, restricted partitions with distinct or odd parts only, or an explicit listing of every partition rather than the count, treat those as separate search intents rather than overloading this landing. Keep n inside the documented bound so free-tier latency stays predictable, and prefer string consumers for the returned value because p(n) leaves the safe-integer range long before five thousand.
What you can do with it
Number-theory homework and contests
Compute exact p(n) for olympiad problems, discrete-math exercises, and automated answer keys that ask for unrestricted integer partitions.
Textbook triangle checks
Verify classic values such as p(5)=7 and p(10)=42 when teaching generating functions or building partition demos.
FAQ
What is the integer partition function p(n)?
p(n) counts the ways to write n as a sum of positive integers when order does not matter. For example p(4)=5 and p(5)=7.
How is this different from compositions?
Compositions count ordered sums (so 1+3 and 3+1 are different). Partitions ignore order, so those two are the same partition of 4.
Why is the value a string instead of a number?
Partition numbers grow past JavaScript safe integers quickly. Decimal strings keep every digit exact for large p(n).
What does it cost?
The browser tool is free and runs locally.
How many partitions does 10 have?
Forty-two. Enter 10 and the result is p(10), which is 42. Other quick checks are p(5), which is 7, and p(0), which is 1 because the empty sum counts once.
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/combo/partition-count \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/combo/partition-count", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/combo/partition-count",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/combo/partition-count", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/combo/partition-count", 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": 5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "combo.partition_count",
"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 | 0 |
max_n | 5000 |
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
The free browser tool and the paid API share one pure function, so classroom demos and automated pipelines never diverge on the same n.
How the partition function p(n) is defined
Declared bounds keep n between zero and five thousand inclusive, which keeps worst-case latency suitable for a free in-browser tool and a lightweight Worker path while still covering contest, classroom, and pipeline needs for exact partition counts.
What you send and what you get back
The integer n must lie from zero through five thousand inclusive. Error messages name the offending field and the rule that failed so form clients and scripts can correct the input without guessing. On success the response always includes the normalized n, value and count and p as the same exact decimal string for p(n), and a short formula string such as p(5) for display. Provide a required integer n under the field n (aliases number, value, or N). Missing fields, non-integers, decimals, and any negative n are rejected with invalid_input and are not charged. Example checks: n equals five yields count seven; n equals ten yields count forty-two; n equals zero yields count one; n equals four yields count five; n equals one yields count one; n equals negative three yields invalid_input because the partition function is not defined for negative arguments in this product rule; n equal to a decimal or a non-numeric string also yields invalid_input. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where integer partitions show up in real work
Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.
Integration use cases
DP and knapsack analysis
Size multiset decomposition state spaces and validate partition-count fixtures inside integer DP pipelines without floating-point tables.
Technical questions
What happens if n is negative?
The request fails with invalid_input. This calculator requires n ≥ 0; negative n is rejected and not charged.