一个矩形的面积为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
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
int n,m,i,j,k;
while(scanf("%d",&n)!=EOF)
{
m=sqrt(n);
if(m*m==n)
printf("%d\n",4*m);
else
{
for(i=m;i<=n;i++)
{
if(n%i==0)
{
k=n/i;
printf("%d\n",(k+i)*2);
break;
}
}
}
}
return 0;
}
李陶冶 (题目提供者)