title: Factoring a number into roughly equal factors
body: <p>I would like to decompose a number into a tuple of numbers as close to each other in size as possible, whose product is the initial number. The inputs are the number <code>n</code> we want to factor and the number <code>m</code> of factors desired.</p>
  
  <p>For the two factor situation (<code>m==2</code>), it is enough to look for the largest factor less than a square root, so I can do something like this</p>
  
  <pre><code>def get_factors(n):
    i = int(n**0.5 + 0.5)
    while n % i != 0:
      i -= 1
    return i, n/i
  </code></pre>
  
  <p>So calling this with <code>120</code> will result in <code>10,12</code>.</p>
  
  <p>I realize there is some ambiguity as to what it means for the numbers to be "close to each other in size". I don't mind if this is interpretted as minimizing <code>Σ(x_i - x_avg)</code> or <code>Σ(x_i - x_avg)^2</code> or something else generally along those lines.</p>
  
  <p>For the <code>m==3</code> case, I would expect that <code>336</code> to produce <code>6,7,8</code> and <code>729</code> to produce <code>9,9,9</code>.</p>
  
  <p>Ideally, I would like a solution for general <code>m</code>, but if someone has an idea even for <code>m==3</code> it would be much appreciated. I welcome general heuristics too. </p>
  
  <p>EDIT: I would prefer to minimize the sum of the factors. Still interested in the above, but if someone has an idea for a way of also figuring out the optimal <code>m</code> value such that the sum of factors is minimal, it'd be great!</p>