結果

問題 No.915 Plus Or Multiple Operation
ユーザー ks2mks2m
提出日時 2019-10-25 22:13:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,074 bytes
コンパイル時間 3,808 ms
コンパイル使用メモリ 76,836 KB
実行使用メモリ 37,304 KB
最終ジャッジ日時 2024-04-24 18:43:00
合計ジャッジ時間 5,240 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 52 ms
37,036 KB
testcase_02 AC 54 ms
36,644 KB
testcase_03 AC 52 ms
36,500 KB
testcase_04 AC 53 ms
36,744 KB
testcase_05 AC 53 ms
36,916 KB
testcase_06 AC 52 ms
37,064 KB
testcase_07 AC 52 ms
37,304 KB
testcase_08 AC 53 ms
37,008 KB
testcase_09 AC 53 ms
36,788 KB
testcase_10 AC 52 ms
36,500 KB
testcase_11 AC 52 ms
36,648 KB
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

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));
		String[] sa = br.readLine().split(" ");
		int q = Integer.parseInt(sa[0]);
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			long a = Integer.parseInt(sa[0]);
			long b = Integer.parseInt(sa[1]);
			long c = Integer.parseInt(sa[2]);

			if (c == 1) {
				System.out.println(a * b);
			} else {
				long ans1 = 0;
				while (a >= c * c) {
					if (a % c > 0) {
						ans1++;
					}
					a /= c;
					ans1++;
				}
				ans1 *= b;
				long ans2 = Long.MAX_VALUE;
				for (int j = 0; j < 3; j++) {
					long x = (long) Math.pow(c, j);
					if (x > a) {
						break;
					}
					long val1 = j;
					long val2 = (a / x + c - 2) / (c - 1);
					long val3 = (a % x + c - 2) / (c - 1);
					long val = val1 + val2 + val3;
					val *= b;
					ans2 = Math.min(ans2, val);
				}
				System.out.println(ans1 + ans2);
			}
		}
		br.close();
	}
}
0