c.Tom and paper

时间:2023-03-09 05:28:08
c.Tom and paper

Tom and paper

Description

There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper.       

Input

In the first line, there is an integer T indicates the number of test cases. In the next T lines, there is only one integer n in every line, indicates the area of paper.         c.Tom and paperc.Tom and paperc.Tom and paperc.Tom and paperc.Tom and paperc.Tom and paperc.Tom and paperc.Tom and paperc.Tom and paper c.Tom and paper  
      

Output

For each case, output a integer, indicates the answer.       

Sample Input

3
2
7
12

Sample Output

6
16
14
题目大意:
已知面积,求最小周长。
分析:
要想求最小周长要已知一条边。C=2*(a/i+i)或C=2*(1+n)将两个进行比较,输出最小值。
注意:
判断i的范围,想到正方形边长=sqrt(n)
代码:
 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int a,c;
for(int i=;i<=sqrt(n);i++)
{
a=*(n+); if(n%i==)
c=*(n/i+i);
if(c<=a)
a=c;
}
printf("%d\n",a);
}
return ;
}