Counting Summations
It is possible to write five as a sum in exactly six different ways: How many different ways can one hundred be written as a sum of at least two positive integers?
Problem Statement
This archive keeps the full statement, math, and original media on the page.
It is possible to write five as a sum in exactly six different ways: \begin {align*} &4 + 1\\ &3 + 2\\ &3 + 1 + 1\\ &2 + 2 + 1\\ &2 + 1 + 1 + 1\\ &1 + 1 + 1 + 1 + 1 \end {align*}
How many different ways can one hundred be written as a sum of at least two positive integers?
Problem 76: Counting Summations
Mathematical Foundation
Definition 1 (Integer Partition). A partition of a non-negative integer is a multiset of positive integers satisfying . Two partitions are identical if and only if they contain the same parts with the same multiplicities. The partition function counts the number of partitions of . By convention, (the empty partition).
Definition 2 (Restricted Partition). Let denote the number of partitions of into parts each at most . Equivalently, counts the number of solutions in non-negative integers to , where represents the multiplicity of part . Note that .
Theorem 1 (Generating Function for ). The ordinary generating function for the partition function is
Proof. For each positive integer , the geometric series encodes the choice of copies of part contributing to the total. The Cauchy product of all such series over yields
Absolute convergence for follows from , since the terms are and converges.
Theorem 2 (Euler’s Pentagonal Number Theorem). As formal power series (and for ):
Proof (Franklin’s Involution). The coefficient of on the left is , where denotes the set of partitions of into distinct parts and is the number of parts.
For , define two parameters:
- : the smallest part.
- : the length of the maximal sequence of consecutive integers descending from . That is, .
Define the map as follows:
- Move A (applicable when , or when and ): Remove the smallest part and add to each of the largest parts . This produces a partition with distinct parts.
- Move B (applicable when , or when Move A is inapplicable): Subtract from each of the largest parts , and insert as a new smallest part. This produces a partition with distinct parts.
One verifies that (i) Moves A and B are mutual inverses, (ii) each changes by exactly , hence reverses the sign , and (iii) the map is undefined (yielding fixed points) precisely when the two moves coincide or become degenerate. This occurs when:
- and : partition is , giving .
- and : gives .
At these fixed points the sign contribution is . For all other , the map pairs each partition with one of opposite sign, so the net contribution cancels.
Theorem 3 (Partition Recurrence via Pentagonal Numbers). For :
where , for , and the sum terminates when both pentagonal arguments become negative.
Proof. Multiplying the generating functions from Theorems 1 and 2:
Extracting the coefficient of for :
Rearranging and noting that yields the stated recurrence.
Theorem 4 (Correctness of Partition DP). Define the array by , for . For and for , perform . Then upon termination, .
Proof. We prove by induction on that after processing part size , the value equals for all .
Base case (): Before any updates, and for . This is correct since the only partition using parts is the empty partition of .
Inductive step: Assume for all before processing part size . The update loop sets for . After this pass, accumulates:
since the forward iteration (increasing ) allows the value to already reflect uses of part . This telescopes to the partition identity , which counts partitions of with parts by conditioning on the multiplicity of part . After , we have .
Remark. The problem asks for partitions into at least two parts, which excludes the trivial partition . The answer is therefore .
Editorial
This is the standard partition DP in unbounded-knapsack form. We process possible part sizes in increasing order, and after part size is handled, the table entry for a sum represents the number of partitions of that use only parts up to .
The update is natural: every partition of can be extended by adding one more part of size , so we add the number of ways to make into the number of ways to make . Because part sizes are introduced in sorted order, the same multiset is never counted in different orders. That is exactly why the DP counts partitions rather than compositions. At the end we subtract one to remove the trivial partition consisting of alone.
Pseudocode
Create a table for sums from 0 to 100 and fill it with zeros.
Set the entry for sum 0 to 1.
For each allowed part size from 1 to 100:
For each target sum that can include this part:
add the number of ways to form the remaining sum after taking one such part
Subtract one to exclude the single-part partition 100.
Return the resulting count.
Complexity Analysis
Time: The nested loops execute iterations, each performing arithmetic. For , this is operations.
Space: The one-dimensional DP array requires entries.
Alternative: The pentagonal number recurrence (Theorem 3) computes each in time, yielding total time.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
const int N = 100;
vector<long long> dp(N + 1, 0);
dp[0] = 1;
// Partition DP: for each part size k, update dp[j] += dp[j - k]
for (int k = 1; k <= N; k++)
for (int j = k; j <= N; j++)
dp[j] += dp[j - k];
// p(100) - 1: exclude the trivial partition 100 = 100
cout << dp[N] - 1 << endl;
return 0;
}
"""
Problem 76: Counting Summations
How many different ways can 100 be written as a sum of at least two positive integers?
Answer: p(100) - 1 = 190569291
"""
def partition_count(n):
"""Compute p(n) via the standard unbounded-knapsack partition DP."""
dp = [0] * (n + 1)
dp[0] = 1
for k in range(1, n + 1):
for j in range(k, n + 1):
dp[j] += dp[j - k]
return dp[n]
def main():
N = 100
answer = partition_count(N) - 1 # exclude the trivial partition n = n
print(answer)
if __name__ == "__main__":
main()