結果

問題 No.376 立方体のN等分 (2)
ユーザー compass19compass19
提出日時 2016-06-06 12:34:18
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,488 bytes
コンパイル時間 2,451 ms
コンパイル使用メモリ 81,044 KB
実行使用メモリ 122,564 KB
最終ジャッジ日時 2024-04-17 05:15:26
合計ジャッジ時間 16,063 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 160 ms
42,324 KB
testcase_01 AC 153 ms
42,472 KB
testcase_02 AC 280 ms
109,372 KB
testcase_03 AC 275 ms
106,336 KB
testcase_04 AC 298 ms
119,068 KB
testcase_05 AC 152 ms
42,792 KB
testcase_06 AC 156 ms
42,388 KB
testcase_07 AC 154 ms
42,376 KB
testcase_08 AC 170 ms
45,732 KB
testcase_09 AC 193 ms
59,992 KB
testcase_10 AC 257 ms
65,252 KB
testcase_11 AC 222 ms
77,928 KB
testcase_12 AC 244 ms
89,344 KB
testcase_13 AC 250 ms
91,476 KB
testcase_14 AC 253 ms
96,836 KB
testcase_15 AC 265 ms
102,864 KB
testcase_16 AC 680 ms
107,428 KB
testcase_17 RE -
testcase_18 AC 265 ms
111,920 KB
testcase_19 RE -
testcase_20 AC 286 ms
115,664 KB
testcase_21 AC 692 ms
115,792 KB
testcase_22 AC 295 ms
118,548 KB
testcase_23 AC 763 ms
119,664 KB
testcase_24 AC 692 ms
120,728 KB
testcase_25 AC 293 ms
120,980 KB
testcase_26 AC 744 ms
121,344 KB
testcase_27 AC 279 ms
121,732 KB
testcase_28 AC 297 ms
122,248 KB
testcase_29 AC 296 ms
121,880 KB
testcase_30 AC 300 ms
122,216 KB
testcase_31 AC 301 ms
122,420 KB
testcase_32 AC 300 ms
122,564 KB
testcase_33 AC 298 ms
122,264 KB
testcase_34 AC 302 ms
122,404 KB
testcase_35 AC 298 ms
122,208 KB
testcase_36 AC 293 ms
122,408 KB
testcase_37 AC 294 ms
122,156 KB
testcase_38 AC 298 ms
122,392 KB
testcase_39 AC 301 ms
122,324 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 (int 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] = (int)(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