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. openfire升级指南

    原文:http://www.liuhaihua.cn/archives/355.html 升级Openfire是和从头开始安装Openfire几乎一样简单.作为升级过程的一部分,它强烈建议您先备份当前 ...

  2. Html_在线客服静态网页

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. mysql使用笔记(二)

    一.启动和关闭mysql服务 windows下 启动 (方法1)管理员权限进入cmd,执行 net start mysql (方法2)管理员权限进入cmd,执行 mysqld -uroot --con ...

  4. 界面显示这个时间格式的js代码: 2016年1月19日 星期二 乙未(羊)年 腊月初十

    today=new Date();function initArray(){ this.length=initArray.arguments.length for(var i=0;i<this. ...

  5. HTML5中的文本级语义

    <p>这篇文章的发布时间是<time datetime="2016-02-26T16:30+08:00" pubdate>今天</time>&l ...

  6. 向html中添加节点

    简单: ①,js中: (function () { var box=document.querySelector("#box"); var con1=document.create ...

  7. python 练习 30

    Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.本章节我们将详细介绍Python的面向对象编程. 如果你以前没有接触过面向对象的编程语言,那你 ...

  8. ThreadLocal 那点事儿

    原文出处: 黄勇 ThreadLocal,直译为“线程本地”或“本地线程”,如果你真的这么认为,那就错了!其实,它就是一个容器,用于存放线程的局部变量,我认为应该叫做 ThreadLocalVaria ...

  9. zoj3822 Domination(概率dp)

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  10. 使用Eclipse构建Maven的SpringMVC项目

    一.直接建立Maven项目方法1.建立Maven项目 接下来使用Eclipse的maven构建一个web项目,以构建SpringMVC项目为例: 1.1 选择建立Maven Project 选择Fil ...