[51NOD]1283 最小周长[数学]
一个矩形的面积为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<cstdio> #include<cmath> int main() { int s; scanf("%d",&s); int max=1,top=sqrt(s); for(int i=top;i>0;i--) if(s%i==0){ max=i; break; } PRintf("%d\n",(max+s/max)*2); return 0; }