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了,这样就不会超时了。
 
 
 
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int t,s;
double m;
scanf("%d",&t);
while(t--)
{
int x,y,c;
int mini=1e9;
scanf("%d",&s);
m=(double)sqrt(s);
for(x=1;x<=m;x++)
{
if(s%x==0)
{
y=s/x;
c=(x+y)*2;
mini=min(c,mini);
}
}
printf("%d\n",mini); }
}
 
 
 
 

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. IntelliJ IDEA 学习(六)内存设置

    小伙伴们经常会发现,在开发的时候,经常遇到内存被占满,导致异常卡顿,有时候提示内存溢出,这时可以通过设置xmx来改善.不过切记最好不要超过内存的1/4 打开 IDEA 安装目录,看到有一个 bin 目 ...

  2. OpenGL的几何变换[转]

    OpenGL的几何变换 1.实验目的: 理解掌握一个OpenGL程序平移.旋转.缩放变换的方法. 2.实验内容: (1)阅读实验原理,运行示范实验代码,掌握OpenGL程序平移.旋转.缩放变换的方法: ...

  3. 快速认识ELK中的L - Logstash

    快速认识ELK中的L - Logstash 原创 2016-12-07 杜亦舒 简介 Logstash 是一个开源的数据采集引擎. Logstash 就像是一个管子,左面接数据源接收数据,右面接存储目 ...

  4. $.each 与$().each()

    在jquery中,遍历对象和数组,经常会用到$().each和$.each(),两个方法.两个方法是有区别的,从而这两个方法在针对不同的操作上,显示了各自的特点. $().each,对于这个方法,在d ...

  5. 向java全台推送数据等

    (1)http://www.cnblogs.com/xdp-gacl/p/3789624.html (2)VenusWebHelper  等等 public void test(){ String f ...

  6. commonJS — DOM操作(for DOM)

    for DOM github: https://github.com/laixiangran/commonJS/blob/master/src/forDOM.js 代码 /** * Created b ...

  7. matlab 自动阈值白平衡算法 程序可编译实现

    一种效果很好的自动白平衡技术(WhiteBalance) 白平衡是图像处理的一个极重要概念.所谓白平衡(英文名称为White Balance),就是对白色物体的还原.当我们用肉眼观看这大千世界时,在不 ...

  8. MATLAB 编程风格指南及注意事项

    MATLAB编程风格指南Richard Johnson 著Genial 译MATLAB 编程风格指南Richard JohnsonVersion 1.5,Oct. 2002版权: Datatool 所 ...

  9. mysql数据库回滚

    在应用$mysqli时,因没常用到数据回滚,老忘,整理下,做个记录. $mysqli->autocommit(FALSE);//自动提交设置关闭 $mysqli->query(" ...

  10. MIRO校验过程

    一.介绍发票校验是物料管理(MM)系统的一部分.它提供物料管理部分和财务会计, 成本控制和资产管理部分的连接.物料管理模块的发票校验为以下目的服务:它完成物料采购的全过程 - 物料采购从采购申请开始, ...