Partition Function p(n) Calculator

Enter a non-negative integer n to get the number of integer partitions p(n).

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.

Try this example →

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.

Comments (1)

  • Editorial team

    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?

Popular calculators

All Calculators