c++:
1 #include <stdio.h> 2 #include <math.h> 3 #include <limits.h> 4 5 int main() 6 { 7 int n; 8 int i,j,k; 9 int ans[3]; 10 int min; 11 while(scanf("%d",&n)!=EOF) 12 { 13 min=INT_MAX; 14 for(i=1;i<=sqrt((double)n)+1;i++) 15 { 16 if(n%i==0) 17 { 18 for(j=1;j<=n/i;j++) 19 { 20 if(n%(i*j)==0) 21 { 22 k=n/(i*j); 23 if(i*j+i*k+j*k<min) 24 { 25 min=i*j+i*k+j*k; 26 ans[0]=i; 27 ans[1]=j; 28 ans[2]=k; 29 } 30 } 31 } 32 } 33 } 34 printf("%d %d %d\n",ans[0],ans[1],ans[2]); 35 } 36 return 0; 37 }
java:
1 //author:pz 2 3 import java.awt.*; 4 import java.io.*; 5 import java.util.*; 6 import java.lang.*; 7 8 public class Main { 9 public static void main(String[] args) { 10 Scanner in = new Scanner(new BufferedInputStream(System.in)); 11 while(in.hasNextInt()){ 12 int i,j,k; 13 int []ans = new int[3]; 14 int min; 15 int n = in.nextInt(); 16 min=Integer.MAX_VALUE; 17 for(i=1; i<=Math.sqrt((double)n)+1; i++) 18 { 19 if(n%i==0) 20 { 21 for(j=1; j<=n/i; j++) 22 { 23 if(n%(i*j)==0) 24 { 25 k=n/(i*j); 26 if(i*j+i*k+j*k<min) 27 { 28 min=i*j+i*k+j*k; 29 ans[0]=i; 30 ans[1]=j; 31 ans[2]=k; 32 } 33 } 34 } 35 } 36 } 37 System.out.println(ans[0]+" "+ans[1]+" "+ans[2]); 38 } 39 } 40 }