Restricted Partition Calculator

Enter an integer n and the number of parts k to count the partitions.

How it is calculated

The tool counts the partitions of n into exactly k positive parts, where order does not matter (so 7+2+1 and 1+2+7 are one partition). It fills a table with the recurrence p(n, k) = p(n − 1, k − 1) + p(n − k, k) and starts from p(0, 0) = 1. The first term covers partitions that contain a part equal to 1 (remove it), the second covers partitions whose parts are all at least 2 (subtract 1 from every part). Inputs are rounded to whole numbers, so 3.6 is treated as 4. n must be between 0 and 200 and k must not exceed n, otherwise there is no result. With k = 0 and n above 0 the count is 0.

Worked example

How many ways can 10 be written as a sum of exactly 3 positive integers? The recurrence gives p(10, 3) = p(9, 2) + p(7, 3) = 4 + 4 = 8. Listing them confirms it: 8+1+1, 7+2+1, 6+3+1, 6+2+2, 5+4+1, 5+3+2, 4+4+2 and 4+3+3. Counts grow quickly: for n = 200 and k = 100 the tool returns 190,569,292.

Try this example →

Common mistakes

  • Counting ordered sums: 7+2+1 and 1+2+7 are the same partition here, so a hand count of compositions will be much larger.
  • Confusing p(n, k), exactly k parts, with the partitions of n into at most k parts, which is a larger number.
  • Allowing zero as a part: every part must be at least 1.
  • Entering k larger than n, which cannot be split into that many positive parts and returns no result.
  • Entering a decimal such as 3.6 and expecting an error: the tool rounds it to 4 and answers for that.

About this calculator

p(n,k) counts the number of ways to write a positive integer n as a sum of exactly k positive parts, ignoring order. It's computed with the classic recurrence p(n,k) = p(n−1,k−1) + p(n−k,k), which splits on whether the smallest part equals 1 or every part can be reduced by 1.

This restricted count is a building block for the broader partition function p(n) and for generating-function techniques in number theory and combinatorics. It's used by math students, competitive programmers, and researchers working on integer partition problems, where counting the ways a number breaks into pieces of a fixed count comes up constantly.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Two quick checks help you trust a result. Adding p(10, k) for k = 1 to 10 gives 1, 5, 8, 9, 7, 5, 3, 2, 1 and 1, which total 42, the number of all partitions of 10. And the count for at most 3 parts is the sum of the first three, 14, rather than the 8 for exactly 3. Inputs go up to n = 200. Are you using this for a puzzle, a programming contest or a proof?

Popular calculators

All Calculators