結果

問題 No.897 compαctree
ユーザー ks2mks2m
提出日時 2019-10-04 21:27:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 2,023 ms
コンパイル使用メモリ 75,144 KB
実行使用メモリ 50,408 KB
最終ジャッジ日時 2024-04-14 10:12:27
合計ジャッジ時間 3,643 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
49,868 KB
testcase_01 AC 55 ms
49,908 KB
testcase_02 AC 55 ms
50,360 KB
testcase_03 AC 55 ms
50,288 KB
testcase_04 AC 55 ms
50,372 KB
testcase_05 AC 56 ms
50,252 KB
testcase_06 AC 55 ms
50,088 KB
testcase_07 AC 57 ms
50,124 KB
testcase_08 AC 56 ms
50,144 KB
testcase_09 AC 56 ms
50,068 KB
testcase_10 AC 55 ms
50,272 KB
testcase_11 AC 56 ms
49,888 KB
testcase_12 AC 56 ms
49,884 KB
testcase_13 AC 55 ms
50,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int q = Integer.parseInt(br.readLine());
		for (int i = 0; i < q; i++) {
			String[] sa = br.readLine().split(" ");
			long n = Integer.parseInt(sa[0]);
			long k = Integer.parseInt(sa[1]);
			if (k == 1) {
				System.out.println(n - 1);
			} else {
				long sum = 0;
				for (int j = 0; j < 40; j++) {
					long b = (long) Math.pow(k, j);
					sum += b;
					if (sum >= n) {
						System.out.println(j);
						break;
					}
				}
			}
		}
		br.close();
	}
}
0