码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5224 Tom and paper

时间:2015-07-02 20:49:26      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5224

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.

$T\leq 10,n\leq {10}^{9}$

Output

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

Sample Input

3
2
7
12

Sample Output

6
16
14

技术分享
 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<map>
 8 using std::min;
 9 using std::cin;
10 using std::cout;
11 using std::endl;
12 using std::find;
13 using std::sort;
14 using std::map;
15 using std::pair;
16 using std::vector;
17 using std::multimap;
18 #define pb(e) push_back(e)
19 #define sz(c) (int)(c).size()
20 #define mp(a, b) make_pair(a, b)
21 #define all(c) (c).begin(), (c).end()
22 #define iter(c) decltype((c).begin())
23 #define cls(arr,val) memset(arr,val,sizeof(arr))
24 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
25 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
26 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
27 const int Max_N = 100010;
28 const int INF = ~0u >> 1;
29 typedef unsigned long long ull;
30 void solve(int n) {
31     int ans = INF;
32     for (int i = 1; (ull)i * i <= n; i++) {
33         if (n % i == 0) ans = min(ans, (i + n / i) << 1);
34     }
35     printf("%d\n", ans);
36 }
37 int main() {
38 #ifdef LOCAL
39     freopen("in.txt", "r", stdin);
40     freopen("out.txt", "w+", stdout);
41 #endif
42     int t, n;
43     scanf("%d", &t);
44     while (t--) {
45         scanf("%d", &n);
46         solve(n);
47     }
48     return 0;
49 }
View Code

hdu 5224 Tom and paper

标签:

原文地址:http://www.cnblogs.com/GadyPu/p/4617008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!