训练1-P

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

Input
输入1个数S(1 <= S <= 10^9)。
Output
输出最小周长。

Sample Input
24
Sample Output
20

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	long i, j, t, s, a[10000]; 
	cin >> s;
	t = 0;
	for (i = 1; i <= sqrt(s); i++)
	{
		if(s%i==0)
		{
			a[t++]=(i+s/i)*2;
		}
	}
	sort(a, a + t);
	cout << a[0] << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41785863/article/details/80947291
今日推荐