title: Minimal Perimeter of Rectangle codility
body: <p>This is the task:</p>
  <p>An integer N is given, representing the area of some rectangle.</p>
  <p>The area of a rectangle whose sides are of length A and B is A * B, and the perimeter is 2 * (A + B).</p>
  <p>The goal is to find the minimal perimeter of any rectangle whose area equals N. The sides of this rectangle should be only integers.</p>
  <p>For example, given integer N = 30, rectangles of area 30 are:</p>
  <pre><code>    (1, 30), with a perimeter of 62,
      (2, 15), with a perimeter of 34,
      (3, 10), with a perimeter of 26,
      (5, 6), with a perimeter of 22.
  </code></pre>
  <p>Write a function:</p>
  <pre><code>int solution(int N); 
  </code></pre>
  <p>that, given an integer N, returns the minimal perimeter of any rectangle whose area is exactly equal to N.</p>
  <p>For example, given an integer N = 30, the function should return 22, as explained above.</p>
  <p>Assume that:</p>
  <pre><code>    N is an integer within the range [1..1,000,000,000].
  </code></pre>
  <p>Complexity:</p>
  <pre><code>    expected worst-case time complexity is O(sqrt(N));
      expected worst-case space complexity is O(1).
  </code></pre>
  <p>It is my solution to codility task <code>MInPerimeterRectangle</code>. It works properly but if we have a test case: &quot; 982451653 &quot; the compiler get an <code>TIMEOUT ERROR</code>. It's because the minimal perimeter of this rectangle is created by sides A = 1 and B = 982451653.</p>
  <p>So i have a question. Is it a possibility to make <strong>this</strong> solution faster?</p>
  <pre><code>class Solution {
          public int solution(int N) {
              
              int A = 0;
              int B = N;
              int perimeter = 0;
              for (A = 1; A &lt;= B; A++) {
                  if (A * B == N){
                      perimeter = 2 * (A + B);
                      System.out.println(&quot;perimeter: &quot; + perimeter);
                  }
                  if (N % (A+1) == 0) 
                      B = N/(A+1);
              }
              System.out.println(&quot;A: &quot; + A);
              
              return perimeter;
          }
          
      }
  </code></pre>