---
# System prepended metadata

title: L10-MinPerimeterRectangle
tags: [Codility_lessons]

---

# L10-MinPerimeterRectangle
###### tags: `Codility_lessons`
## Question
https://app.codility.com/programmers/lessons/10-prime_and_composite_numbers/min_perimeter_rectangle/
## Key
前一題的變化
## Reference
## Solution
```cpp=
int solution(int N) {
    // write your code in C++14 (g++ 6.2.0)
    long x = 1;
    long d;
    long tmp;
    long min = 1000000000;
    if(N == 1)
    {
        return 4;
    }
    for(;x*x <= N ; x++)
    {
        if(N % x == 0)
        {
            d = N/x;
           tmp = d + x;
           if(tmp < min)
           {
               min = tmp;
           }
        }
    }
    return 2*min;
}
```