51nod 1283 最小周长(水题)

题目来源: Codility
基准时间限制: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

i*j=C,i越靠近j,i+j越小。
 1 #include <iostream>
 2 #include <cmath>
 3 using namespace std;
 4 int main()
 5 {
 6     int s;
 7     cin>>s;
 8     int i=sqrt(s);
 9     int j=s/i;
10     while(i*j!=s)
11     {
12         if(i*j>s)
13             i--;
14         else if(i*j<s)
15             j++;
16     }
17     cout<<2*(i+j)<<endl;
18     return 0;
19 }
View Code
 
原文地址:https://www.cnblogs.com/onlyli/p/7254094.html