51Nod-1283 最小周长

xiaoxiao2021-02-28  11

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

#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int s; cin>>s; double a=sqrt(s); int i=(int)a; for(;i>=1;i--){ double b=s*1.0/i; if(b==(int)b){ cout<<2*(i+int(b))<<endl; break; } } return 0; }
转载请注明原文地址: https://www.6miu.com/read-2650298.html

最新回复(0)