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. JAVA 程序设置运行内存

    1.修改jdk设置 2.如果不行则 一般安装完eclipse之后,在安装目录下你应该可以看到有一个 eclipse.ini 文件,对了,就是在这个文件里面修改 -vmargs:说明后面是VM的参数 - ...

  2. spring 编程式事务管理和声明式事务管理

    编程式事务管理 Spring 的编程式事务管理概述 在 Spring 出现以前,编程式事务管理对基于 POJO 的应用来说是唯一选择.用过 Hibernate 的人都知道,我们需要在代码中显式调用be ...

  3. Python项目实战

    编程只有不断练习才能掌握其精髓,多练练网上的习题和项目,才能掌握python的精髓. Python的模块和包是出了名的多,因此你不必自己从底层开始写起,只需要看懂模块和包的使用文档就可以了,因此掌握一 ...

  4. 微信小程序初体验(上)

    版权声明:本文由练小习原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/204 来源:腾云阁 https://www.qclo ...

  5. 关于OneProxy推广

    通过以下关键字 分库分表,读写分离,连接池,跨库查询,开源数据库,MySQL,高性能,并行查询 在搜索引擎中,都找不到OneProxy和OneSQL的影子

  6. 鼠标经过导航中li时,一个彩色模块跟着鼠标移动

    1.鼠标经过导航中li时,一个活动的li跟随鼠标移动,最终移动到鼠标的停留的位置.(如需鼠标离开后让活动的li回到初始位置,则用jq hover事件,当鼠标离开时,给活动的li设置left是0) 2. ...

  7. 025-ViewData、ViewBag与TempData概述

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

  8. python 练习 28

    ython pass是空语句,是为了保持程序结构的完整性. pass 不做任何事情,一般用做占位语句. Python 语言 pass 语句语法格式如下: pass 实例: #!/usr/bin/pyt ...

  9. 添加SSH密钥到GitHub

    $ clip < ~/.ssh/id_rsa.pubbash: /c/Users/UsersName/.ssh/id_rsa.pub: No such file or directory [转] ...

  10. JMeter基础知识

    JMeter介绍 JMeter是开源的性能测试工具和接口测试工具,工作原理和Loadrunner一样:作为浏览器和WebServer之间的网关,捕获Browser请求和WebServer响应,然后通过 ...