照片摆放
描述
每张图片都是一个正方形,尺寸为 1 个单位乘 1 个单位。
例如,小星现在有 12 张照片
所以这个方的矩形周长,14 个单位,尺寸为 3×4。
请你帮小星求出 n(1<=n<=65000) 张照片,最小的周长是多少,当然还要求出矩形的尺寸。
输入描述
输入多行每一行都表示 照片的个数 n
当 n=0 的时候停止输入
输出描述
输出多行,每一行三个数,分别表示周长、矩形的宽和长,(宽<=长)
样例输入 1
100
15
195
0
样例输出 1
40 10 10
16 3 5
56 13 15
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
while (cin >> n && n != 0) {
int square_root = sqrt(n);
int width, height, perimeter;
if (square_root * square_root == n) {
width = height = square_root;
perimeter = 2 * (width + height);
} else {
width = ceil(sqrt(n));
height = floor(sqrt(n));
perimeter = 2 * (width + height);
}
cout << perimeter << " " << width << " " << height << endl;
}
return 0;
}