Class Solution
-
- All Implemented Interfaces:
public final class Solution3669 - Balanced K-Factor Decomposition.
Medium
Given two integers
nandk, split the numberninto exactlykpositive integers such that the product of these integers is equal ton.Return any one split in which the maximum difference between any two numbers is minimized. You may return the result in any order.
Example 1:
Input: n = 100, k = 2
Output: 10,10
Explanation:
The split
[10, 10]yields10 * 10 = 100and a max-min difference of 0, which is minimal.Example 2:
Input: n = 44, k = 3
Output: 2,2,11
Explanation:
Split
[1, 1, 44]yields a difference of 43Split
[1, 2, 22]yields a difference of 21Split
[1, 4, 11]yields a difference of 10Split
[2, 2, 11]yields a difference of 9
Therefore,
[2, 2, 11]is the optimal split with the smallest difference 9.Constraints:
<code>4 <= n <= 10<sup>5</sup></code>
2 <= k <= 5kis strictly less than the total number of positive divisors ofn.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntArrayminDifference(Integer n, Integer k)-
-
Method Detail
-
minDifference
final IntArray minDifference(Integer n, Integer k)
-
-
-
-