結果

問題 No.1664 Unstable f(n)
ユーザー ks2mks2m
提出日時 2021-09-03 21:25:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 930 bytes
コンパイル時間 2,603 ms
コンパイル使用メモリ 77,860 KB
実行使用メモリ 41,924 KB
最終ジャッジ日時 2024-05-09 01:24:33
合計ジャッジ時間 8,800 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
41,564 KB
testcase_01 AC 130 ms
41,924 KB
testcase_02 AC 129 ms
41,884 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 122 ms
41,544 KB
testcase_07 AC 116 ms
41,588 KB
testcase_08 AC 125 ms
41,580 KB
testcase_09 AC 125 ms
41,612 KB
testcase_10 AC 125 ms
41,212 KB
testcase_11 AC 124 ms
41,624 KB
testcase_12 AC 115 ms
41,204 KB
testcase_13 AC 128 ms
41,664 KB
testcase_14 AC 113 ms
41,492 KB
testcase_15 AC 127 ms
41,492 KB
testcase_16 AC 129 ms
41,784 KB
testcase_17 AC 113 ms
41,372 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 126 ms
41,404 KB
testcase_21 AC 130 ms
41,784 KB
testcase_22 AC 117 ms
41,908 KB
testcase_23 AC 127 ms
41,524 KB
testcase_24 AC 116 ms
41,656 KB
testcase_25 AC 130 ms
41,592 KB
testcase_26 AC 127 ms
41,452 KB
testcase_27 AC 128 ms
41,524 KB
testcase_28 AC 130 ms
41,624 KB
testcase_29 AC 131 ms
41,368 KB
testcase_30 AC 131 ms
41,480 KB
testcase_31 AC 128 ms
41,684 KB
testcase_32 AC 126 ms
41,584 KB
testcase_33 AC 125 ms
41,836 KB
testcase_34 AC 127 ms
41,536 KB
testcase_35 AC 132 ms
41,292 KB
testcase_36 AC 132 ms
41,624 KB
testcase_37 AC 126 ms
41,468 KB
testcase_38 AC 127 ms
41,444 KB
testcase_39 AC 127 ms
41,428 KB
testcase_40 AC 125 ms
41,712 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 + 1;
		for (int j = 1; j < 60; j++) {
			int i = root(n, j);
			long k = n - power(i, j);
			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