最小周长

基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题

一个矩形的面积为S,已知该矩形的边长都是整数,求所有满足条件的矩形中,周长的最小值。例如:S = 24,那么有{1 24} {2 12} {3 8} {4 6}这4种矩形,其中{4 6}的周长最小,为20。
Input
输入1个数S(1 <= S <= 10^9)。
Output
输出最小周长。
Input示例
24
Output示例
20

最短的就是最中间的 

附AC代码:

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 
 5 int main(){
 6     int n,cnt;
 7     cin>>n;
 8     int t=sqrt(n);
 9     //cout<<t<<endl;
10     if(n%t==0){
11         cnt=n/t+t;
12     }
13     else{
14         while(t--){
15             if(n%t==0){
16                 break;
17             }
18         }
19         cnt=n/t+t;
20     }
21     cout<<cnt*2<<endl;
22     return 0;
23 }
原文地址:https://www.cnblogs.com/Kiven5197/p/5862955.html