title: Find closest factor to a number, of a number
body: <p>I am trying to automate the finding of the closest factor of a number to another number;</p>
  
  <p><strong>Example:</strong></p>
  
  <p>Closest factor of 700 to 30 is 28 (30 does not go into 700, but 28 does).</p>
  
  <p>An obvious solution is just to get all the factors of 700 and do a simple distance calculation to find the nearest factor to 30, but this seems to be inefficient.</p>
  
  <p>Another solution is to find all the base prime factors, like:</p>
  
  <pre><code>private List&lt;Integer&gt; getPrimeFactors(int upTo) {
      List&lt;Integer&gt; result = new ArrayList&lt;&gt;();
      for (int i = 2; i &lt;= upTo; i++) {
          if (upTo % i == 0) {
              result.add(i);
          }
      }
      return result;
  }
  </code></pre>
  
  <p>And multiplying each of these numbers together to get all the combinations, and therefore find the closest.</p>
  
  <p>I am trying to programme this so it is automated. 
  Any better solutions? </p>