結果

問題 No.376 立方体のN等分 (2)
ユーザー compass19compass19
提出日時 2016-06-06 12:52:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 612 ms / 5,000 ms
コード長 1,168 bytes
コンパイル時間 2,602 ms
コンパイル使用メモリ 81,320 KB
実行使用メモリ 122,432 KB
最終ジャッジ日時 2024-04-24 13:50:26
合計ジャッジ時間 17,258 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
42,424 KB
testcase_01 AC 158 ms
42,164 KB
testcase_02 AC 320 ms
109,156 KB
testcase_03 AC 315 ms
106,536 KB
testcase_04 AC 338 ms
119,344 KB
testcase_05 AC 156 ms
42,336 KB
testcase_06 AC 159 ms
42,596 KB
testcase_07 AC 156 ms
42,404 KB
testcase_08 AC 171 ms
45,708 KB
testcase_09 AC 208 ms
59,560 KB
testcase_10 AC 243 ms
65,344 KB
testcase_11 AC 251 ms
77,700 KB
testcase_12 AC 276 ms
89,244 KB
testcase_13 AC 275 ms
91,084 KB
testcase_14 AC 289 ms
96,828 KB
testcase_15 AC 300 ms
102,324 KB
testcase_16 AC 557 ms
107,212 KB
testcase_17 AC 303 ms
109,200 KB
testcase_18 AC 322 ms
111,648 KB
testcase_19 AC 314 ms
113,240 KB
testcase_20 AC 329 ms
115,468 KB
testcase_21 AC 567 ms
115,792 KB
testcase_22 AC 340 ms
118,428 KB
testcase_23 AC 587 ms
119,684 KB
testcase_24 AC 568 ms
120,624 KB
testcase_25 AC 342 ms
120,916 KB
testcase_26 AC 612 ms
121,532 KB
testcase_27 AC 344 ms
121,504 KB
testcase_28 AC 347 ms
122,252 KB
testcase_29 AC 346 ms
122,364 KB
testcase_30 AC 347 ms
122,432 KB
testcase_31 AC 351 ms
122,256 KB
testcase_32 AC 348 ms
122,296 KB
testcase_33 AC 340 ms
122,348 KB
testcase_34 AC 348 ms
122,100 KB
testcase_35 AC 344 ms
122,168 KB
testcase_36 AC 343 ms
122,156 KB
testcase_37 AC 345 ms
122,036 KB
testcase_38 AC 332 ms
121,672 KB
testcase_39 AC 338 ms
122,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int l = (int)Math.floor(Math.sqrt(n));
        int cbrt = (int)Math.cbrt(n);
        long []y = new long [l];
        int tail = 0;
        for (long i = 1; i <= l; i++){
            if (n%i == 0)   y[tail++] = i;
        }
        long []x = new long [tail];
        for (int i = 0; i < tail; i++){
            x[i] = (long)(n/y[i]);
        }
        long m = -1;
        long a,b;
        for (int i = 0; i < tail; i++){
            if (y[i] <= cbrt){
                a = y[i];
                long sqrt = (long)Math.sqrt(n/a);
                for (int j = i; j < tail; j++){
                    b = y[j];
                    if (n%(a*b) == 0 && b <= sqrt){
                        if (m == -1){
                            m = a+b+(long)(n/(a*b))-3;
                        }else{
                            m = Math.min(a+b+(long)(n/(a*b))-3, m);
                        }
                    }
                }
            }
        }
        System.out.println(m+" "+(n-1));
    }
}
0