51nod Minimum Perimeter

Source: Internet
Author: User

1283 minimum perimeter topic Source: codility Base time limit: 1 seconds space limit: 131072 KB Score: 5 Difficulty: 1-level algorithm topic collection concerns a rectangle's area is s, the side length of the rectangle is known to be integers, the minimum value of the circumference of all the rectangles that satisfy the condition is obtained. For example: S = 24, then there are 12 rectangles with {1 24} {2 3} {8 4} {6 4}, where {4 6} has a minimum perimeter of 20. Input
`Enter a number s (1 <= s <= 10^9).`
Output
`Output minimum perimeter.The first direct traversal timeout, by the mathematical theorem, the circumference of a certain square area of the largest, the area of a certain square circumference of the smallest, from the Int (sqrt (perimeter)) to the left and right to traverse can improve efficiency`
`#include <iostream>#include<algorithm>#include<vector>#include<cstring>#include<cstdio>#include<cmath>using namespaceStd;typedefLong LongLL;#defineMAXN 1001#defineINF 0x3f3f3f3fll Solve (ll N) {ll m=inf,t; LL a= (LL) sqrt ((Double) n); LL D= A*a>n? -1:1; T=A;  while(n%t) {T+=D; }    return(t+n/t) *2;}intMain () {LL n; CIN>>N; cout<<solve (n) <<Endl; return 0;}`

51nod Minimum Perimeter

Related Keywords:

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.