Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Lets say you have two numbers <code>x</code> and <code>y</code> such that <code>x*y = z</code> (where <code>z</code> is your constant number)</p> <ul> <li><p>We want <code>xy =z</code> for a constant <code>z</code> and we want to minimize <code>f(x) = x+y</code></p></li> <li><p>We know that <code>xy = z</code> <code>so x = z/y</code> (assuming z is not 0, otherwise it's fairly easy to prove there is no solution)</p></li> <li><p>So we need to minimize <code>f(x) = z/x + x</code></p></li> <li><p>Derivate <code>f(x)</code> to get <code>f'(x) = 1 - z/(x^2)</code></p></li> <li><p>Find min/max points by equating the derivative to 0 (using <a href="http://en.wikipedia.org/wiki/Fermat%27s_theorem_%28stationary_points%29" rel="nofollow">Fermat's theorem</a> getting:</p> <p><code>z/(x^2) = 1</code> which brings you <code>x^2 = z</code></p></li> </ul> <p>Meaning the only possible point of maximum is <code>x^2 = z</code> which means <code>x=√z</code> which means <code>y=x</code></p> <p><strong>However, you already knew that.</strong></p> <ul> <li><p>We know that for every <code>x</code> and <code>y</code> it holds that <code>(x+y)(x-y) = x^2-y^2</code></p></li> <li><p>If we write <code>x=a+b</code> and <code>y=a-b</code> for some a and b we get that <code>(a-b)(a-b)</code> is maximal if y is 0 meaning in our example <code>x=y</code>.</p></li> <li><p>Which bring us to the strategy Gilbert Le Blanc suggested if you're only accepting integer solutions, start at the root of <code>z</code> and try increasing decreasing from it. The first number you match is the result.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload