結果
問題 | No.1664 Unstable f(n) |
ユーザー | Jetman |
提出日時 | 2021-09-03 23:12:37 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,306 bytes |
コンパイル時間 | 2,678 ms |
コンパイル使用メモリ | 79,072 KB |
実行使用メモリ | 38,004 KB |
最終ジャッジ日時 | 2024-12-15 17:31:39 |
合計ジャッジ時間 | 6,990 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
36,856 KB |
testcase_01 | AC | 59 ms
36,932 KB |
testcase_02 | AC | 55 ms
36,936 KB |
testcase_03 | AC | 53 ms
36,828 KB |
testcase_04 | AC | 55 ms
36,892 KB |
testcase_05 | AC | 53 ms
37,008 KB |
testcase_06 | AC | 54 ms
37,112 KB |
testcase_07 | AC | 53 ms
37,160 KB |
testcase_08 | AC | 54 ms
36,836 KB |
testcase_09 | AC | 53 ms
36,960 KB |
testcase_10 | AC | 54 ms
36,724 KB |
testcase_11 | AC | 74 ms
37,700 KB |
testcase_12 | AC | 137 ms
38,004 KB |
testcase_13 | AC | 134 ms
37,656 KB |
testcase_14 | AC | 122 ms
37,880 KB |
testcase_15 | AC | 89 ms
37,984 KB |
testcase_16 | AC | 112 ms
37,832 KB |
testcase_17 | AC | 142 ms
37,592 KB |
testcase_18 | AC | 149 ms
37,840 KB |
testcase_19 | AC | 159 ms
37,832 KB |
testcase_20 | AC | 124 ms
37,748 KB |
testcase_21 | AC | 55 ms
36,944 KB |
testcase_22 | AC | 54 ms
37,208 KB |
testcase_23 | AC | 56 ms
36,824 KB |
testcase_24 | AC | 57 ms
36,724 KB |
testcase_25 | AC | 56 ms
36,808 KB |
testcase_26 | AC | 56 ms
36,724 KB |
testcase_27 | AC | 54 ms
36,960 KB |
testcase_28 | AC | 54 ms
36,864 KB |
testcase_29 | AC | 57 ms
36,904 KB |
testcase_30 | AC | 55 ms
36,960 KB |
testcase_31 | WA | - |
testcase_32 | AC | 60 ms
36,808 KB |
testcase_33 | AC | 54 ms
36,936 KB |
testcase_34 | AC | 55 ms
37,104 KB |
testcase_35 | AC | 122 ms
37,656 KB |
testcase_36 | AC | 55 ms
36,944 KB |
testcase_37 | AC | 82 ms
37,860 KB |
testcase_38 | AC | 55 ms
36,760 KB |
testcase_39 | AC | 58 ms
36,852 KB |
testcase_40 | AC | 72 ms
37,716 KB |
ソースコード
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 (tmp + 1 <= sqrt) 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()); } } }