Partition Function p(n) Calculator
Enter a non-negative integer n to get the number of integer partitions p(n).
Result
How it is calculated
p(n) counts the ways to write n as a sum of positive whole numbers when order is ignored. The tool builds a table with dynamic programming: it starts with p[0] = 1 and all other entries 0, then for each part size k from 1 to n it updates p[j] += p[j − k] for j from k to n. After the last pass, p[n] is the answer. n must be a whole number from 0 to 299; negative numbers, decimals and anything above 299 give no result, because from 300 the count no longer fits exactly in the floating-point numbers used. p(0) is defined as 1, and the result is shown with thousands separators.
Worked example
For n = 5 the table starts as [1, 0, 0, 0, 0, 0] for p[0] to p[5]. Allow parts of size 1: [1, 1, 1, 1, 1, 1]. Add parts of size 2: [1, 1, 2, 2, 3, 3]. Add size 3: [1, 1, 2, 3, 4, 5]. Add size 4: [1, 1, 2, 3, 5, 6]. Add size 5: [1, 1, 2, 3, 5, 7]. The last entry gives p(5) = 7. The seven partitions are 5, 4+1, 3+2, 3+1+1, 2+2+1, 2+1+1+1 and 1+1+1+1+1.
Common mistakes
- Counting orderings as different partitions. 3+1+1, 1+3+1 and 1+1+3 are one partition. Counting every order gives compositions, which grow as 2n−1, far faster than p(n).
- Forgetting that n itself is a partition. p(4) = 5, not 4, because the single part 4 counts along with 3+1, 2+2, 2+1+1 and 1+1+1+1.
- Entering a value above 299 and expecting an approximation. The tool only returns exact values and gives nothing for 300 or more.
- Entering a decimal or a negative number. Only whole numbers from 0 upward are valid.
- Reading p(n) as the number of partitions into distinct parts or into odd parts only. This tool counts all partitions with no restriction on repeated parts.
About this calculator
This calculator computes the integer partition function p(n), a classic object of study in number theory: the number of distinct ways to write n as a sum of positive integers, where order doesn't matter (so 4 itself, 3+1, 2+2, 2+1+1 and 1+1+1+1 give p(4) = 5). The function grows explosively — p(100) already exceeds 190 million.
p(n) is famous for the Hardy–Ramanujan asymptotic formula that approximates it for large n, and for Ramanujan's remarkable congruences (like p(5n+4) always divisible by 5). This calculator returns the exact value, computed for any n up to 299 (p(300) exceeds the range that can be computed exactly here).
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
You can test Ramanujan's congruence yourself with this tool. Enter 4, 9 and 14, the values of 5n + 4, and you get 5, 30 and 135, each divisible by 5. Then try 5, 6 or 8 and watch the divisibility vanish. The largest exact value available here is p(299), about 8.6 quadrillion, which is the reason for the 299 limit. Have you found another pattern in the values worth showing?