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
#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); } }
时间: 2024-11-25 08:45:06