結果

問題 No.1664 Unstable f(n)
ユーザー tentententen
提出日時 2023-04-17 18:21:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,456 bytes
コンパイル時間 4,422 ms
コンパイル使用メモリ 91,244 KB
実行使用メモリ 37,228 KB
最終ジャッジ日時 2024-04-20 21:37:51
合計ジャッジ時間 6,407 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
36,940 KB
testcase_01 AC 49 ms
36,576 KB
testcase_02 AC 48 ms
36,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 47 ms
37,012 KB
testcase_11 AC 47 ms
36,948 KB
testcase_12 AC 47 ms
37,024 KB
testcase_13 AC 46 ms
37,228 KB
testcase_14 AC 47 ms
37,008 KB
testcase_15 AC 47 ms
36,972 KB
testcase_16 AC 47 ms
36,944 KB
testcase_17 AC 47 ms
37,024 KB
testcase_18 AC 47 ms
37,036 KB
testcase_19 AC 47 ms
36,996 KB
testcase_20 AC 48 ms
36,828 KB
testcase_21 AC 48 ms
37,048 KB
testcase_22 AC 48 ms
36,972 KB
testcase_23 AC 48 ms
36,744 KB
testcase_24 AC 46 ms
36,884 KB
testcase_25 AC 51 ms
36,980 KB
testcase_26 AC 46 ms
37,124 KB
testcase_27 AC 46 ms
36,808 KB
testcase_28 AC 45 ms
37,208 KB
testcase_29 AC 45 ms
36,956 KB
testcase_30 AC 49 ms
37,000 KB
testcase_31 AC 47 ms
36,828 KB
testcase_32 AC 48 ms
36,728 KB
testcase_33 AC 47 ms
36,836 KB
testcase_34 AC 47 ms
36,944 KB
testcase_35 AC 45 ms
36,956 KB
testcase_36 AC 46 ms
37,012 KB
testcase_37 AC 48 ms
36,996 KB
testcase_38 AC 47 ms
36,944 KB
testcase_39 AC 46 ms
36,728 KB
testcase_40 AC 46 ms
36,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        long ans = n - 1;
        for (int i = 2; i <= 60; i++) {
            long left = 1;
            long right = Long.MAX_VALUE / 2;
            while (right - left > 1) {
                long m = (left + right) / 2;
                if (pow(m, i) <= n) {
                    left = m;
                } else {
                    right = m;
                }
            }
            ans = Math.min(ans, i + left + n - pow(left, i));
        }
        System.out.println(ans);
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            if (Long.MAX_VALUE / 2 / x <= x) {
                return Long.MAX_VALUE / 2;
            }  else {
                return pow(x * x, p / 2);
            }
        } else {
            long tmp = pow(x, p - 1);
            if (Long.MAX_VALUE / 2 / tmp <= x) {
                return Long.MAX_VALUE / 2;
            } else {
                return pow(x, p - 1) * x;
            }
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0