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
 
 
  题目大意:给出一张纸的面积,要求输出这张纸的最少周长。
 
  思路:纸的面积等于长乘以宽,即一个数等于它的两个质因子数之积,当有多个质因子时,
每两个质因子数之积等于该数的分为一组,分别以这两个质因子作为长宽算出其周长再比较大小,最后输出最小的那个值。
由于时间为1s,给出的n的最大值为1e9,直接写1-n一定会超时,所以先将其开平方就减为1e4-1e5了,这样就不会超时了。
 
 
 
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. int t,s;
  9. double m;
  10. scanf("%d",&t);
  11. while(t--)
  12. {
  13. int x,y,c;
  14. int mini=1e9;
  15. scanf("%d",&s);
  16. m=(double)sqrt(s);
  17. for(x=1;x<=m;x++)
  18. {
  19. if(s%x==0)
  20. {
  21. y=s/x;
  22. c=(x+y)*2;
  23. mini=min(c,mini);
  24. }
  25. }
  26. printf("%d\n",mini);
  27.  
  28. }
  29. }
 
 
 
 

Problem C HDU 5224的更多相关文章

  1. HDU 5224 Tom and paper(最小周长)

    HDU 5224 Tom and paper(最小周长) Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d &a ...

  2. A * B Problem Plus HDU - 1402 (FFT)

    A * B Problem Plus HDU - 1402 (FFT) Calculate A * B.  InputEach line will contain two integers A and ...

  3. hdu 5224 Tom and paper

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5224 Tom and paper Description There is a piece of pa ...

  4. 2013多校联合3 G The Unsolvable Problem(hdu 4627)

    2013-07-30 20:35 388人阅读 评论(0) 收藏 举报 http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Pr ...

  5. Train Problem I hdu 1022(栈)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=1022 题意:给出火车的进站与出站顺序,判断是否可以按照给出的出站顺序出站. #include < ...

  6. Train Problem I (HDU 100题纪念)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  7. BestCoder Round #70 Jam's math problem(hdu 5615)

    Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...

  8. Polynomial Problem(hdu 1296 表达式求值)

    We have learned how to obtain the value of a polynomial when we were a middle school student. If f(x ...

  9. 刷题总结——Tree chain problem(HDU 5293 树形dp+dfs序+树状数组)

    题目: Problem Description Coco has a tree, whose vertices are conveniently labeled by 1,2,…,n.There ar ...

随机推荐

  1. Android开发面试经——4.常见Android进阶笔试题(更新中...)

      Android开发(29)  版权声明:本文为寻梦-finddreams原创文章,请关注:http://blog.csdn.net/finddreams 关注finddreams博客:http:/ ...

  2. nginx系统真正有效的图片防盗链完整设置详解

    原文:http://www.wufangbo.com/nginx-fang-dao-lian/ 关于nginx防盗链的方法网上有很多教程,都可以用,但是我发现很多教程并不完整,所做的防盗链并不是真正的 ...

  3. Python 学习笔记 - 10.类(Class) 1

    定义 Python 的 Class 比较特别,和我们习惯的静态语言类型定义有很大区别. 1. 使用一个名为 __init__ 的方法来完成初始化.2. 使用一个名为 __del__ 的方法来完成类似析 ...

  4. java语法体系

    乱写的不具备参考性,只是一个备忘录

  5. COM组件(MFC篇)

    目录 第1章创建进程内组件    1 1.1 目标    1 1.2 创建项目    3 1.2.1 VC++6.0    3 1.2.2 VC++2010    4 1.2.3 VC++6.0与VC ...

  6. SAP 通过屏幕字段查看透明表

    我要查看创建采购订单屏幕上抬头部分付款条件的这个透明表中的字段. 图1. 1.首先准备好MM模块中的常用透明表. 图2. 2.把光标放在字段上,按F1,再点击图中技术信息按钮. 图3. 3.在弹出的技 ...

  7. Git 分支管理是一门艺术

    转载: Git 分支管理是一门艺术 1 要确保:团队成员从主分支(master)获得的都是处于可发布状态的代码,而从开发分支(develop)应该总能够获得最新开发进展的代码. 2 "辅助分 ...

  8. FileReader本地预览图片

    <body> <p><label>请选择一个图像文件:</label><input type="file" id=" ...

  9. 025-ViewData、ViewBag与TempData概述

    Action向View传递数据很简单,方式也很多,最直接的就是我们向View传递Model,这本身就是MVC的意义所在.如果是显示一些消息,像是错误信息,可以使用ViewData.ViewBag.Te ...

  10. jmeter笔记6

     一.图形报表   图表底部参数的含义如下: 样本数目是总共发送到服务器的请求数. 最新样本是代表时间的数字,是服务器响应最后一个请求的时间. 吞吐量是服务器每分钟处理的请求数.  平均值是总运行时间 ...