結果

問題 No.376 立方体のN等分 (2)
ユーザー compass19compass19
提出日時 2016-06-06 12:46:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 701 ms / 5,000 ms
コード長 1,490 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 79,692 KB
実行使用メモリ 133,492 KB
最終ジャッジ日時 2024-04-24 13:50:09
合計ジャッジ時間 15,645 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
54,892 KB
testcase_01 AC 129 ms
54,444 KB
testcase_02 AC 276 ms
121,568 KB
testcase_03 AC 278 ms
117,180 KB
testcase_04 AC 301 ms
130,256 KB
testcase_05 AC 139 ms
54,736 KB
testcase_06 AC 134 ms
42,580 KB
testcase_07 AC 123 ms
42,172 KB
testcase_08 AC 130 ms
45,468 KB
testcase_09 AC 175 ms
60,076 KB
testcase_10 AC 225 ms
65,164 KB
testcase_11 AC 224 ms
90,472 KB
testcase_12 AC 242 ms
100,548 KB
testcase_13 AC 232 ms
101,848 KB
testcase_14 AC 241 ms
107,480 KB
testcase_15 AC 270 ms
113,844 KB
testcase_16 AC 622 ms
118,396 KB
testcase_17 AC 267 ms
120,284 KB
testcase_18 AC 294 ms
122,628 KB
testcase_19 AC 287 ms
124,576 KB
testcase_20 AC 283 ms
126,048 KB
testcase_21 AC 674 ms
126,712 KB
testcase_22 AC 298 ms
129,196 KB
testcase_23 AC 674 ms
130,424 KB
testcase_24 AC 659 ms
131,848 KB
testcase_25 AC 310 ms
132,232 KB
testcase_26 AC 701 ms
132,172 KB
testcase_27 AC 303 ms
133,104 KB
testcase_28 AC 309 ms
133,100 KB
testcase_29 AC 308 ms
132,832 KB
testcase_30 AC 310 ms
133,004 KB
testcase_31 AC 312 ms
133,336 KB
testcase_32 AC 311 ms
133,260 KB
testcase_33 AC 304 ms
133,372 KB
testcase_34 AC 301 ms
132,728 KB
testcase_35 AC 300 ms
132,532 KB
testcase_36 AC 304 ms
133,060 KB
testcase_37 AC 307 ms
133,492 KB
testcase_38 AC 310 ms
133,040 KB
testcase_39 AC 309 ms
133,044 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);
                        }
                    }
                    b = x[i];
                    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