結果

問題 No.1330 Multiply or Divide
ユーザー ks2mks2m
提出日時 2021-01-08 22:15:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,052 bytes
コンパイル時間 2,523 ms
コンパイル使用メモリ 76,960 KB
実行使用メモリ 62,028 KB
最終ジャッジ日時 2024-04-28 03:29:56
合計ジャッジ時間 12,966 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 320 ms
59,228 KB
testcase_02 AC 55 ms
37,048 KB
testcase_03 AC 56 ms
37,148 KB
testcase_04 AC 53 ms
36,988 KB
testcase_05 AC 54 ms
37,028 KB
testcase_06 AC 244 ms
55,904 KB
testcase_07 WA -
testcase_08 AC 344 ms
61,348 KB
testcase_09 AC 338 ms
61,136 KB
testcase_10 AC 350 ms
61,000 KB
testcase_11 AC 355 ms
61,164 KB
testcase_12 AC 378 ms
61,532 KB
testcase_13 AC 54 ms
36,932 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 53 ms
37,108 KB
testcase_17 WA -
testcase_18 AC 322 ms
60,952 KB
testcase_19 AC 328 ms
61,252 KB
testcase_20 AC 317 ms
61,256 KB
testcase_21 AC 327 ms
61,084 KB
testcase_22 AC 323 ms
60,764 KB
testcase_23 AC 333 ms
62,028 KB
testcase_24 AC 53 ms
37,152 KB
testcase_25 AC 53 ms
37,148 KB
testcase_26 AC 52 ms
36,920 KB
testcase_27 AC 52 ms
37,028 KB
testcase_28 AC 53 ms
37,088 KB
testcase_29 AC 53 ms
36,900 KB
testcase_30 AC 54 ms
36,984 KB
testcase_31 AC 53 ms
37,172 KB
testcase_32 AC 52 ms
36,988 KB
testcase_33 AC 52 ms
36,964 KB
testcase_34 AC 328 ms
55,140 KB
testcase_35 AC 158 ms
44,708 KB
testcase_36 AC 261 ms
54,312 KB
testcase_37 AC 264 ms
53,776 KB
testcase_38 AC 222 ms
49,500 KB
testcase_39 AC 183 ms
46,168 KB
testcase_40 AC 215 ms
45,608 KB
testcase_41 AC 150 ms
44,536 KB
testcase_42 AC 248 ms
53,232 KB
testcase_43 AC 271 ms
54,072 KB
testcase_44 WA -
testcase_45 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 n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int p = Integer.parseInt(sa[2]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] b = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			if (a[i] > m) {
				System.out.println(1);
				return;
			}
			b[i] = a[i];
			while (b[i] % p == 0) {
				b[i] /= p;
			}
			c[i] = m / a[i] + 1;
		}

		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			if (b[i] == 1) {
				continue;
			}
			long x = 1;
			int cnt = 0;
			while (x < c[i]) {
				cnt++;
				x *= b[i];
			}
			ans = Math.min(ans, cnt + 1);
		}
		if (ans == Integer.MAX_VALUE) {
			ans = -1;
		}
		System.out.println(ans);
	}
}
0