結果

問題 No.1664 Unstable f(n)
ユーザー ks2mks2m
提出日時 2021-09-03 21:27:19
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 974 bytes
コンパイル時間 2,484 ms
コンパイル使用メモリ 77,280 KB
実行使用メモリ 54,292 KB
最終ジャッジ日時 2024-05-09 01:38:41
合計ジャッジ時間 9,489 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
41,296 KB
testcase_01 AC 135 ms
41,688 KB
testcase_02 AC 135 ms
41,540 KB
testcase_03 AC 133 ms
41,716 KB
testcase_04 AC 122 ms
40,440 KB
testcase_05 AC 121 ms
40,356 KB
testcase_06 AC 120 ms
40,252 KB
testcase_07 AC 130 ms
41,268 KB
testcase_08 AC 129 ms
41,704 KB
testcase_09 AC 131 ms
41,660 KB
testcase_10 AC 133 ms
41,640 KB
testcase_11 AC 132 ms
41,508 KB
testcase_12 AC 129 ms
41,384 KB
testcase_13 AC 130 ms
41,296 KB
testcase_14 AC 131 ms
41,836 KB
testcase_15 AC 134 ms
41,524 KB
testcase_16 AC 133 ms
41,532 KB
testcase_17 AC 134 ms
41,460 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 122 ms
40,536 KB
testcase_21 AC 132 ms
41,448 KB
testcase_22 AC 120 ms
40,248 KB
testcase_23 AC 126 ms
41,284 KB
testcase_24 AC 131 ms
41,460 KB
testcase_25 AC 129 ms
41,720 KB
testcase_26 AC 132 ms
41,220 KB
testcase_27 AC 119 ms
40,092 KB
testcase_28 AC 131 ms
41,248 KB
testcase_29 AC 133 ms
41,356 KB
testcase_30 AC 118 ms
40,456 KB
testcase_31 AC 133 ms
41,484 KB
testcase_32 AC 119 ms
40,048 KB
testcase_33 AC 130 ms
41,420 KB
testcase_34 AC 130 ms
41,308 KB
testcase_35 AC 120 ms
40,024 KB
testcase_36 AC 130 ms
41,472 KB
testcase_37 AC 128 ms
41,244 KB
testcase_38 AC 128 ms
41,380 KB
testcase_39 AC 117 ms
40,180 KB
testcase_40 AC 114 ms
40,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();

		long ans = n;
		for (int j = 1; j < 60; j++) {
			int i = root(n, j);
			long k = n - power(i, j);
			if (k < 0) {
				throw new Exception();
			}
			ans = Math.min(ans, i + j + k);
		}
		System.out.println(ans);
	}

	static int root(long x, int n) {
		int ng = 1000000001;
		int ok = 1;
		while (ng - ok > 1) {
			int mid = (ok + ng) / 2;
			if (Math.pow(mid, n) <= Long.MAX_VALUE) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		ng = ok + 1;
		ok = 1;
		while (ng - ok > 1) {
			int mid = (ok + ng) / 2;
			if (power(mid, n) <= x) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		return ok;
	}

	static long power(long x, long n) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2);
		val = val * val;
		if (n % 2 == 1) {
			val = val * x;
		}
		return val;
	}
}
0