結果

問題 No.1664 Unstable f(n)
ユーザー JetmanJetman
提出日時 2021-09-03 23:22:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 2,330 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 78,012 KB
実行使用メモリ 51,304 KB
最終ジャッジ日時 2023-08-22 01:17:05
合計ジャッジ時間 6,485 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,468 KB
testcase_01 AC 47 ms
49,508 KB
testcase_02 AC 46 ms
49,420 KB
testcase_03 AC 46 ms
49,540 KB
testcase_04 AC 45 ms
49,536 KB
testcase_05 AC 45 ms
49,484 KB
testcase_06 AC 46 ms
49,496 KB
testcase_07 AC 45 ms
49,500 KB
testcase_08 AC 46 ms
49,964 KB
testcase_09 AC 45 ms
49,408 KB
testcase_10 AC 46 ms
49,520 KB
testcase_11 AC 63 ms
49,380 KB
testcase_12 AC 127 ms
50,596 KB
testcase_13 AC 121 ms
50,904 KB
testcase_14 AC 113 ms
50,872 KB
testcase_15 AC 76 ms
50,944 KB
testcase_16 AC 103 ms
51,304 KB
testcase_17 AC 137 ms
50,788 KB
testcase_18 AC 141 ms
50,996 KB
testcase_19 AC 148 ms
50,888 KB
testcase_20 AC 116 ms
50,600 KB
testcase_21 AC 46 ms
49,424 KB
testcase_22 AC 45 ms
49,448 KB
testcase_23 AC 46 ms
49,492 KB
testcase_24 AC 46 ms
49,456 KB
testcase_25 AC 46 ms
49,676 KB
testcase_26 AC 45 ms
49,428 KB
testcase_27 AC 44 ms
49,544 KB
testcase_28 AC 45 ms
49,836 KB
testcase_29 AC 45 ms
49,900 KB
testcase_30 AC 45 ms
49,548 KB
testcase_31 AC 46 ms
49,496 KB
testcase_32 AC 51 ms
50,292 KB
testcase_33 AC 47 ms
49,576 KB
testcase_34 AC 49 ms
49,872 KB
testcase_35 AC 113 ms
50,764 KB
testcase_36 AC 46 ms
49,424 KB
testcase_37 AC 71 ms
50,900 KB
testcase_38 AC 44 ms
49,400 KB
testcase_39 AC 48 ms
49,444 KB
testcase_40 AC 60 ms
49,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        No1664UnstableFn solver = new No1664UnstableFn();
        solver.solve(1, in, out);
        out.close();
    }

    static class No1664UnstableFn {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            long n = in.nextLong();
            long ans = n;
            long tmp = toLong((Math.sqrt(n)));
            ans = Math.min(ans, tmp + 2 + (n - tmp * tmp));
            for (long i = 2; i * i * i <= n; i++) {
                long k = toLong((Math.log(n) / Math.log(i)));
                if (Math.pow(i, k) > n) {
                    out.println(i + " " + k);
                }
                ans = Math.min(ans, i + k + (n - toLong(Math.pow(i, k))));

            }
            out.println(ans);
        }

        private long toLong(double sqrt) {
            long tmp = (long) sqrt;
            if (Math.abs(tmp + 1.0 - sqrt) < 0.00000001) return tmp + 1;
            return tmp;
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st = new StringTokenizer("");

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || (!st.hasMoreElements())) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

0