Minimum Cost to Split into Ones

You are given an integer n.

In one operation, you may split an integer x into two positive integers a and b such that a + b = x.

The cost of this operation is a * b.

Return an integer denoting the minimum total cost required to split the integer n into n ones.

Example 1
Inputn = 3
Output3
One optimal sequence costs 2 to split 3 into 1 and 2, then costs 1 to split 2 into 1 and 1, for a total cost of 3.
Example 2
Inputn = 4
Output6
One optimal sequence costs 4 to split 4 into 2 and 2, then costs 1 for each 2 split into 1 and 1, for a total cost of 6.

Constraints

  • 1 <= n <= 500

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate