The Partition Count
HardAcc. 71.2%
+45 XP 25
Additive Combinations
The partition function $p(n)$ represents the number of ways of writing the integer $n$ as a sum of positive integers. Example: $p(4) = 5$. {4}, {3+1}, {2+2}, {2+1+1}, {1+1+1+1}.
The Assignment
Your function receives a parameter n.
- Use an iterative approach (nested loops or logic) to calculate $p(n)$.
- Print the final count.
01EXAMPLE 1
Input
n = 4Output
5Explanation: 5 ways to sum to 4.
Constraints
- For efficiency, use the pentagonal number theorem logic in a loop.
- Handle n=0 as result 1.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
n4
Expected Output
5
Click RUN to test your solution