Balanced K-Factor Decomposition

Given two integers n and k, split the number n into exactly k positive integers such that the product of these integers is equal to n.

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
Inputn = 100, k = 2
Output[10,10]
The split [10, 10] yields 10 * 10 = 100 and a max-min difference of 0, which is minimal.
Example 2
Inputn = 44, k = 3
Output[2,2,11]
Among the listed valid splits, [2, 2, 11] has the smallest difference, 9.

Constraints

  • 4 <= n <= 10^5
  • 2 <= k <= 5
  • k is strictly less than the total number of positive divisors of n.

Asked at 2 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