結果

問題 No.1330 Multiply or Divide
ユーザー ks2mks2m
提出日時 2021-01-08 22:23:06
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,009 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 78,176 KB
実行使用メモリ 70,540 KB
最終ジャッジ日時 2024-04-28 03:43:07
合計ジャッジ時間 14,875 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 376 ms
70,540 KB
testcase_02 AC 50 ms
36,916 KB
testcase_03 AC 47 ms
36,544 KB
testcase_04 AC 47 ms
36,964 KB
testcase_05 AC 48 ms
36,692 KB
testcase_06 AC 318 ms
61,352 KB
testcase_07 WA -
testcase_08 AC 335 ms
61,372 KB
testcase_09 AC 361 ms
61,784 KB
testcase_10 AC 384 ms
61,276 KB
testcase_11 AC 379 ms
61,332 KB
testcase_12 AC 343 ms
61,520 KB
testcase_13 AC 50 ms
36,628 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 46 ms
36,796 KB
testcase_17 WA -
testcase_18 AC 352 ms
61,744 KB
testcase_19 AC 376 ms
61,572 KB
testcase_20 AC 355 ms
61,712 KB
testcase_21 AC 383 ms
61,764 KB
testcase_22 AC 362 ms
61,392 KB
testcase_23 AC 386 ms
61,624 KB
testcase_24 AC 50 ms
36,480 KB
testcase_25 AC 49 ms
36,172 KB
testcase_26 AC 49 ms
36,316 KB
testcase_27 AC 47 ms
36,728 KB
testcase_28 AC 52 ms
36,800 KB
testcase_29 AC 50 ms
36,768 KB
testcase_30 AC 51 ms
36,716 KB
testcase_31 AC 50 ms
36,528 KB
testcase_32 AC 46 ms
36,672 KB
testcase_33 AC 47 ms
37,060 KB
testcase_34 AC 376 ms
59,548 KB
testcase_35 AC 160 ms
46,100 KB
testcase_36 AC 286 ms
58,016 KB
testcase_37 AC 281 ms
55,684 KB
testcase_38 AC 232 ms
50,260 KB
testcase_39 AC 176 ms
46,904 KB
testcase_40 AC 217 ms
45,516 KB
testcase_41 AC 155 ms
45,460 KB
testcase_42 AC 265 ms
54,044 KB
testcase_43 AC 284 ms
56,628 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

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 ans = Integer.MAX_VALUE;
		label:
		for (int i = 0; i < n; i++) {
			long x = 1;
			Set<Long> set = new HashSet<>();
			set.add(x);
			int cnt = 0;
			while (x <= m) {
				cnt++;
				x *= a[i];
				if (x > m) {
					break;
				}
				if (!set.add(x)) {
					continue label;
				}
				while (x % p == 0) {
					x /= p;
				}
			}
			ans = Math.min(ans, cnt);
		}
		if (ans == Integer.MAX_VALUE) {
			ans = -1;
		}
		System.out.println(ans);
	}
}
0