結果

問題 No.897 compαctree
ユーザー htensaihtensai
提出日時 2019-12-07 11:39:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 72,280 KB
実行使用メモリ 56,128 KB
最終ジャッジ日時 2023-08-26 06:06:48
合計ジャッジ時間 4,930 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,696 KB
testcase_01 AC 130 ms
55,688 KB
testcase_02 AC 130 ms
55,660 KB
testcase_03 AC 129 ms
55,472 KB
testcase_04 AC 131 ms
54,024 KB
testcase_05 AC 129 ms
55,964 KB
testcase_06 AC 128 ms
55,780 KB
testcase_07 AC 130 ms
56,128 KB
testcase_08 AC 130 ms
55,844 KB
testcase_09 AC 130 ms
56,004 KB
testcase_10 AC 129 ms
55,768 KB
testcase_11 AC 129 ms
55,980 KB
testcase_12 AC 128 ms
55,432 KB
testcase_13 AC 128 ms
56,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    sb.append(getCount(sc.nextInt(), sc.nextInt())).append("\n");
		}
		System.out.print(sb);
   }
   
   static int getCount(long n, int k) {
       if (k == 1) {
           return (int)(n - 1);
       }
       int idx = 0;
       while (n > 0) {
           n -= (long)(Math.pow(k, idx));
           idx++;
       }
       return idx - 1;
   }
}
0