Description
Beer Lovers Club makes regular parties. They hate warm beer, but club’s refrigerator is too small to store enough beer for the whole company. So they decided to order a special super-big beer refrigerator. The new refrigerator should be a parallelepiped a × b × c and store exactly n cubical 1 × 1 × 1 beer boxes (the club has n members). To decrease losses of cold, the total area of the surface of the refrigerator must be as small as possible.
For example, if the capacity of the refrigerator must be 12, the possible variants are:
Dimensions | Surface Area | |
3 × 2 × 2 | 32 | |
4 × 3 × 1 | 38 | |
6 × 2 × 1 | 40 | |
12 × 1 × 1 | 50 |
The best variant in this case is 3 × 2 × 2.
Help the beer lovers to find the optimal dimensions of their new refrigerator.
Input
Output
Sample Input
12
Sample Output
3 2 2
Hint
#include<stdio.h>
#include<math.h>
int main(){
int i,j;
long n,a,b,c,d,e,f,l[3];
scanf("%ld",&n);
f=1+2*n;
d=(long)(pow(n*1.0,1.0/3.0));
for(a=1;a<=d;a++){
if((n%a)==0){
e=(long)(n/a);
for(c=d;c<=n;c++){
if((e%c)==0){
b=(long)(e/c);
if(f>=(a*b+b*c+a*c)){
f=a*b+b*c+a*c;
l[0]=a;
l[1]=b;
l[2]=c;
}
}
}
}
}
for(i=0;i<2;i++)
for(j=0;j<2-i;j++){
if(l[j]<l[j+1]){
f=l[j];
l[j]=l[j+1];
l[j+1]=f;
}
}
printf("%ld %ld %ld\n",l[0],l[1],l[2]);
return 0;
}