hwangnk1004 / Algorithm

0 stars 0 forks source link

StepByStep #block #251

Open hwangnk1004 opened 4 years ago

hwangnk1004 commented 4 years ago

import java.util.Scanner;

public class Main { public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);

    int testcase = scanner.nextInt();
    int sum = 100000000;

    for (int i = 0; i < testcase; i++) {
        int n = scanner.nextInt();

        for (int a = 1; a * a <= n; a++) {
            for (int b = a; b <= n; b++) {
                int ab = a * b;
                if (ab > n) {
                    break;
                }
                for (int c = b; c <= n; c++) {
                    int abc = a * b * c;

                    if (abc > n) {
                        break;
                    } else if (abc == n) {
                        if (a <= b && b <= c) {
                            sum = Math.min(sum, a * b * 2 + a * c * 2 + b * c * 2);

                        }
                    }
                }
            }
        }
        System.out.println(sum);
        sum=100000000;
    }
}

}