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. [css] 【转载】 精简高效的CSS命名准则/方法

    原文链接:http://www.zhangxinxu.com/wordpress/2010/09/%E7%B2%BE%E7%AE%80%E9%AB%98%E6%95%88%E7%9A%84css%E5 ...

  2. Node.js superagent 采集 URL 编码问题

    今天在用Node学习采集的时候遇到一个问题,如这个链接地址 http://www.meishij.net/胡萝卜  就是用浏览器的方式访问链接可以打开,但用superagent 去模拟请求,就请求不到 ...

  3. HBase启动和停止命令

    启动HBase集群: bin/start-hbase.sh 单独启动一个HMaster进程: bin/hbase-daemon.sh start master 单独停止一个HMaster进程: bin ...

  4. drupal里面的ajax最粗浅的理解-流程

    1,  form里面的ajax所在地表单元素有一个事件,激发system/ajax,相应的有ajax_form_callback(), 会把被改变的元素值传到form_state[values]中, ...

  5. centos7命令

    查看ip ip addr ip link 添加服务 systemctl enable nginx 添加防火墙端口 firewall-cmd --zone=public --add-port=80/tc ...

  6. 【bzoj1043】下落的圆盘

    [bzoj1043]下落的圆盘 题意 有n个圆盘从天而降,后面落下的可以盖住前面的.求最后形成的封闭区域的周长.看下面这副图, 所有的红色线条的总长度即为所求. \(1\leq n\leq 1000\ ...

  7. 扩展Date的DateAdd方法--计算日期

    Date.prototype.DateAdd = function(strInterval, Number) { var dtTmp = this; switch (strInterval) { ca ...

  8. Android 开源简单控件

    Android开源系列分类 查看 CircleImageView 自定义圆形控件的使用 添加依赖 ‘de.hdodenhof:circleimageview:2.1.0' 作用:无论你设置的图片是什么 ...

  9. 一些简单css3效果的整理

    代码: html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  10. android浮动搜索框

    android浮动搜索框的配置比较繁琐,需要配置好xml文件才能实现onSearchRequest()方法. 1.配置搜索的XML配置文件​,新建文件searchable.xml,保存在res/xml ...