結果

問題 No.375 立方体のN等分 (1)
ユーザー tentententen
提出日時 2022-10-14 11:31:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 249 ms / 5,000 ms
コード長 1,511 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 75,432 KB
実行使用メモリ 54,388 KB
最終ジャッジ日時 2023-09-08 19:36:22
合計ジャッジ時間 8,123 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
52,484 KB
testcase_01 AC 76 ms
52,280 KB
testcase_02 AC 113 ms
53,616 KB
testcase_03 AC 69 ms
51,620 KB
testcase_04 AC 70 ms
51,932 KB
testcase_05 AC 71 ms
50,688 KB
testcase_06 AC 73 ms
50,892 KB
testcase_07 AC 88 ms
52,520 KB
testcase_08 AC 106 ms
53,680 KB
testcase_09 AC 83 ms
52,976 KB
testcase_10 AC 94 ms
53,732 KB
testcase_11 AC 94 ms
54,060 KB
testcase_12 AC 95 ms
53,792 KB
testcase_13 AC 97 ms
54,016 KB
testcase_14 AC 156 ms
53,396 KB
testcase_15 AC 100 ms
53,580 KB
testcase_16 AC 99 ms
53,780 KB
testcase_17 AC 210 ms
53,460 KB
testcase_18 AC 163 ms
53,700 KB
testcase_19 AC 100 ms
54,388 KB
testcase_20 AC 88 ms
54,044 KB
testcase_21 AC 90 ms
53,852 KB
testcase_22 AC 249 ms
53,748 KB
testcase_23 AC 100 ms
53,848 KB
testcase_24 AC 90 ms
52,612 KB
testcase_25 AC 115 ms
53,784 KB
testcase_26 AC 99 ms
53,744 KB
testcase_27 AC 101 ms
54,336 KB
testcase_28 AC 91 ms
53,460 KB
testcase_29 AC 88 ms
53,312 KB
testcase_30 AC 95 ms
54,304 KB
testcase_31 AC 99 ms
53,692 KB
testcase_32 AC 88 ms
52,656 KB
testcase_33 AC 99 ms
53,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        System.out.println(calc1(n) + " " + (n - 1));
    }
    
    static long calc1(long x) {
        long ans = x - 1;
        for (long i = 2; i <= Math.sqrt(x); i++) {
            if (x % i == 0) {
                ans = Math.min(ans, i - 1 + calc2(x / i));
            }
        }
        return ans;
    }
    
    static long calc2(long x) {
        long ans = x - 1;
        for (long i = 2; i <= Math.sqrt(x); i++) {
            if (x % i == 0) {
                ans = Math.min(ans, i - 1 + x / i - 1);
            }
        }
        return ans;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0