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. 
9
 

Output

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

Sample Input

3 2 7 12
 

Sample Output

6 16 14
 
题意:
已知矩形面积求最小周长;;;;
n*m=s;
2(n+m)=2(n+s/n);
当n最接近sqrt(s)时周长最小!!
 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 int main(){
 5     int t;cin>>t;
 6     while(t--){
 7         int n;cin>>n;
 8         int m=floor(sqrt(n)+0.5);
 9         int sum=0;
10         for(int i=m;i>0;i--){
11             if(n%i==0){
12                 sum=max((i+n/i)*2,sum);
13                 break;
14             }
15         }
16         cout<<sum<<endl;
17     }
18 return 0;
19 }
View Code

 

相关文章:

  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-06-13
  • 2021-12-03
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案