結果

問題 No.1176 少ない質問
ユーザー ks2mks2m
提出日時 2020-08-21 21:30:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 1,000 ms
コード長 952 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 76,968 KB
実行使用メモリ 41,864 KB
最終ジャッジ日時 2024-04-23 05:29:41
合計ジャッジ時間 5,486 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
41,152 KB
testcase_01 AC 118 ms
41,060 KB
testcase_02 AC 111 ms
41,340 KB
testcase_03 AC 124 ms
41,724 KB
testcase_04 AC 116 ms
40,092 KB
testcase_05 AC 121 ms
41,492 KB
testcase_06 AC 115 ms
41,612 KB
testcase_07 AC 115 ms
41,408 KB
testcase_08 AC 113 ms
41,280 KB
testcase_09 AC 114 ms
40,348 KB
testcase_10 AC 103 ms
41,864 KB
testcase_11 AC 113 ms
40,120 KB
testcase_12 AC 116 ms
41,312 KB
testcase_13 AC 123 ms
41,420 KB
testcase_14 AC 120 ms
40,968 KB
testcase_15 AC 121 ms
41,132 KB
testcase_16 AC 123 ms
41,504 KB
testcase_17 AC 122 ms
41,244 KB
testcase_18 AC 117 ms
40,348 KB
testcase_19 AC 119 ms
40,084 KB
testcase_20 AC 123 ms
41,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

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

		long ans = a;
		for (int i = 2; i < 64; i++) {
			int r = root(a, i);
			if (power(r, i) < a) {
				r++;
			}
			long val = r * i;
			ans = Math.min(ans, val);
		}
		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