Tom and paper

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5224

题意:

  给出矩形的面积,求出最小的周长。

样例:

Sample Input

3
2
7
12
 

Sample Output

6
16
14
思路:
这个题只需要注意时间就可以了。
  刚开始就就是直接从1开始循环找出满足条件的后比较,结果超时了。。。。
后来又开始从n/2开始查找,这个不需要比较只要找到满足条件就可以了可是还是超时了。。。。
最后是从sqrt()开始才过的。
 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 int i;
 5 int main()
 6 {
 7 int t,n;
 8 cin>>t;
 9 while(t--)
10 {
11     cin>>n;
12 int    m;
13 for(i=sqrt(n);i<=n;i++)
14 {
15     if(n%i==0) 
16     {    m=i+n/i;
17       break;
18     }
19   }
20 cout<<m*2<<endl;
21  }
22 return 0;
23 }
 
原文地址:https://www.cnblogs.com/fenhong/p/4694242.html