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.

  1. Use an iterative approach (nested loops or logic) to calculate $p(n)$.
  2. Print the final count.

01EXAMPLE 1

Inputn = 4
Output5

Explanation: 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
JavaScript
Loading...
3 Hidden

Input Arguments

n4

Expected Output

5

Click RUN to test your solution