結果

問題 No.376 立方体のN等分 (2)
ユーザー Grenache
提出日時 2016-06-08 20:07:49
言語 Java
(openjdk 23)
結果
AC  
実行時間 416 ms / 5,000 ms
コード長 1,051 bytes
コンパイル時間 3,967 ms
コンパイル使用メモリ 79,272 KB
実行使用メモリ 42,460 KB
最終ジャッジ日時 2024-11-06 23:29:21
合計ジャッジ時間 15,066 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;


public class Main_yukicoder375 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();

        List<Long> divisors = new ArrayList<>();
        for (long i = 1; i * i <= n; i++) {
        	if (n % i == 0) {
        		divisors.add(i);
        		if (i != n / i) {
        			divisors.add(n / i);
        		}
        	}
        }
        Collections.sort(divisors);

        long min = n - 1;
        long max = n - 1;
        for (int i = 0; i < divisors.size(); i++) {
    		long x = divisors.get(i);
    		if (x * x * x > n) {
    			break;
    		}
        	for (int j = i; j < divisors.size(); j++) {
        		long y = divisors.get(j);
        		if (x * y * y > n) {
        			break;
        		}
        		if (n % (x * y) != 0) {
        			continue;
        		}
        		long z = n / (x * y);

        		min = Math.min(min, (x - 1) + (y - 1) + (z - 1));
        	}
        }

        System.out.printf("%d %d\n", min, max);

        sc.close();
    }
}
0