結果

問題 No.1330 Multiply or Divide
ユーザー ks2mks2m
提出日時 2021-01-08 22:11:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 76,560 KB
実行使用メモリ 61,864 KB
最終ジャッジ日時 2024-04-28 03:23:13
合計ジャッジ時間 10,842 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 289 ms
58,900 KB
testcase_02 AC 47 ms
36,800 KB
testcase_03 AC 44 ms
36,560 KB
testcase_04 AC 41 ms
36,760 KB
testcase_05 AC 40 ms
36,800 KB
testcase_06 AC 201 ms
55,416 KB
testcase_07 WA -
testcase_08 AC 282 ms
60,576 KB
testcase_09 AC 300 ms
60,736 KB
testcase_10 AC 270 ms
60,708 KB
testcase_11 AC 281 ms
60,832 KB
testcase_12 AC 319 ms
61,400 KB
testcase_13 AC 43 ms
36,744 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 42 ms
36,560 KB
testcase_17 WA -
testcase_18 AC 273 ms
60,440 KB
testcase_19 AC 270 ms
60,748 KB
testcase_20 AC 266 ms
60,652 KB
testcase_21 AC 256 ms
60,076 KB
testcase_22 AC 262 ms
60,444 KB
testcase_23 WA -
testcase_24 AC 42 ms
36,184 KB
testcase_25 AC 41 ms
36,532 KB
testcase_26 WA -
testcase_27 AC 50 ms
36,480 KB
testcase_28 AC 43 ms
36,556 KB
testcase_29 AC 41 ms
36,796 KB
testcase_30 AC 40 ms
37,060 KB
testcase_31 AC 40 ms
36,800 KB
testcase_32 AC 41 ms
36,980 KB
testcase_33 AC 41 ms
36,904 KB
testcase_34 AC 265 ms
52,916 KB
testcase_35 AC 145 ms
45,208 KB
testcase_36 AC 225 ms
53,724 KB
testcase_37 AC 217 ms
53,076 KB
testcase_38 AC 186 ms
48,664 KB
testcase_39 AC 142 ms
44,800 KB
testcase_40 AC 166 ms
45,040 KB
testcase_41 AC 127 ms
44,416 KB
testcase_42 AC 207 ms
53,716 KB
testcase_43 AC 215 ms
53,040 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) / a[i];
		}

		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