HDU 5224 Tom and paper (Bestcoder Round #40)

Source: Internet
Author: User
Tags square root

Title Link: Tom and paper


Surface:

Tom and paperTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 679 Accepted Submission (s): 432


Problem Descriptionthere is a piece of paper in front of Tom, it length and width are integers. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper.
Inputin the first line, there was an integer T indicates the number of the test cases. In the next T-lines, there is only one of the integer-n-Every line, indicates the area of paper.
t ≤ Span class= "mn" id= "mathjax-span-5" style= ">10 , n ≤ 10 9
Outputfor each case, output a integer, indicates the answer.
Sample Input
32712

Sample Output
61614

Sourcebestcoder Round #40

Solving:

If the circumference is fixed, take the value near the half value, the area is the largest. Conversely, take the square root near the longest perimeter.


Code:

#include <iostream> #include <cmath>using namespace Std;int main () {    int t,n,root;    cin>>t;    while (t--)    {      cin>>n;      ROOT=SQRT (1.0*n);      for (int i=root;; i--)      {      if (n%i==0)      {      cout<<2* (i+n/i) <<endl;        Break;}}}        


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5224 Tom and paper (Bestcoder Round #40)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.