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