当前位置:网站首页>Haut OJ 1243: simple mathematical problems

Haut OJ 1243: simple mathematical problems

2022-07-05 05:17:00 hunziHang

Problem description :

Here we go again. 209 It's time to rush to answer math problems once a day , The last time cds It's hard , This time ykc Mengxin gave them a simple math problem , It's really simple

, Is to give you a rectangular area , Find its minimum perimeter , Is it simple , ha-ha , But they just couldn't figure out what I could do , I have to leave the problem to you .

Input :

In the first line, enter a number to represent the test instance t

Enter a number for each group of test cases s(1<=s<=10^9) Represents the area of the rectangle

Output :

Output the minimum perimeter of each test instance

The sample input :

1
24

Sample output :

20

Cause analysis :

Find the minimum perimeter , That is to find the minimum sum of two adjacent sides , It is similar to inequality , That is, the closer the two sides are equal , That is, the sum of two sides is the smallest , So you can square the area first +1( Because rounding down ); Then decrease downward to find Can be s Divisible data .


Solution :

#include<bits/stdc++.h>
using namespace std;
#define endl'\n'
int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin>>t;
  while(t--)
  {
     long long s,l;
     cin>>s;
     l=sqrt(double(s))+1;
     for(int i=l;i>0;i--)
        if(s%i==0)
     {
           cout<<2*(i+s/i)<<endl;
           break;
     }
  }
}

原网站

版权声明
本文为[hunziHang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140622509195.html