Maths & numbers

Integer partition calculator with allowed parts

Count unordered partitions using your allowed positive part sizes, with unlimited reuse and a step-by-step count table.

Your numbers

Use commas or spaces. Sizes may repeat in a partition; repeated entries in this list are merged.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A partition expresses a target as an unordered sum of positive integers. Here the allowed part sizes are supplied by you and may be reused without limit. For example, allowing 1 and 3 does not permit the part 2. Reordering summands never creates another answer. The dynamic program admits one size at a time and counts each multiset of parts once, using exact integer totals.

THE FORMULAways[0] = 1; for each allowed part a, update ways[s] ← ways[s] + ways[s−a] for increasing s.

A worked example

For target 6 and allowed parts 1 and 3, there are three partitions: 1+1+1+1+1+1, 3+1+1+1, and 3+3. Writing 1+3+1+1 does not add another partition because it is a rearrangement of the second. With allowed parts 2 and 4 instead, target 6 has two partitions: 2+2+2 and 4+2.

Good to know

The target is an integer from zero through 500. Supply at most 50 positive sizes, each at most 500. Sizes larger than the target have no effect. Duplicate allowed sizes are merged. Fixed numbers of parts, per-size inventory limits and ordered compositions are different problems and are not inferred.

Order is the crucial difference from compositions

The default target six with sizes one and three can be checked by deciding how many threes appear. Zero threes leaves six ones; one three leaves three ones; two threes leaves none. These three possibilities exhaust the choices. In an ordered composition, moving the three among the ones would produce different sequences. That is intentionally not counted here.

Admitting sizes in a fixed order prevents those permutations from being counted repeatedly. When processing a size a, the update at sum s extends partitions of s − a using another a. Increasing s allows unlimited copies of that same size. Changing that loop to decreasing s would instead allow each listed size at most once, so loop direction encodes a real mathematical assumption.

Three unordered partitions make six using only ones and threes6 = 1 + 1 + 1 + 1 + 1 + 16 = 3 + 1 + 1 + 16 = 3 + 3
For target 6 and allowed sizes 1 and 3, there are three partitions: six ones; one three and three ones; or two threes. Order never creates a new partition.

The greatest common divisor of all allowed part sizes must divide any reachable positive target. This necessary condition can rule out a sum, but it does not itself count partitions.

Zero has one partition, while some positive targets have none

The empty collection of parts is the single partition of zero. This is why ways[0] starts at one: it lets the first allowed part begin a valid sum. All positive targets begin with zero ways. With allowed sizes 4 and 6, target 5 stays at zero because no combination reaches it. A zero result is therefore meaningful and is not a failed calculation.

Repeated entries such as 1, 1, 3 do not create different types of ones and are merged before counting. If distinguishable item types are intended, a different model is needed. The unrestricted partition calculator already includes every positive size up to the target, while this page enforces your supplied set. Neither unrestricted partitions nor the existing bounded ordered-composition calculator is a substitute for that restriction. The table reports the target count after each size is admitted, exposing where new possibilities arise.

A few questions, answered

Can I use an allowed size more than once?

Yes. Reuse is unlimited. The list specifies allowed sizes, not a stock of individual pieces.

Do allowed sizes above the target change the result?

No. Positive summands cannot exceed the target, so those sizes cannot appear in any valid partition.

Find your calculator

Start typing to explore the library.