[LeetCode] Minimum Cost to Split into Ones

3857. 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.

1
2
3
4
5
6
class Solution {
public:
int minCost(int n) {
return 1ll * n * (n - 1) / 2;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/minimum-cost-to-split-into-ones/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.