結果

問題 No.1330 Multiply or Divide
ユーザー ks2mks2m
提出日時 2021-01-08 22:24:40
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,021 bytes
コンパイル時間 2,563 ms
コンパイル使用メモリ 78,248 KB
実行使用メモリ 62,024 KB
最終ジャッジ日時 2024-04-28 05:47:30
合計ジャッジ時間 16,119 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 412 ms
61,344 KB
testcase_02 AC 54 ms
40,680 KB
testcase_03 AC 52 ms
37,096 KB
testcase_04 AC 51 ms
36,952 KB
testcase_05 AC 51 ms
36,896 KB
testcase_06 AC 352 ms
61,744 KB
testcase_07 AC 1,079 ms
61,024 KB
testcase_08 AC 395 ms
62,024 KB
testcase_09 AC 465 ms
61,772 KB
testcase_10 AC 445 ms
61,684 KB
testcase_11 AC 394 ms
61,928 KB
testcase_12 AC 427 ms
61,392 KB
testcase_13 AC 51 ms
36,880 KB
testcase_14 AC 54 ms
37,008 KB
testcase_15 AC 52 ms
36,692 KB
testcase_16 AC 51 ms
37,052 KB
testcase_17 AC 51 ms
37,092 KB
testcase_18 AC 387 ms
61,324 KB
testcase_19 AC 415 ms
61,972 KB
testcase_20 AC 389 ms
61,836 KB
testcase_21 AC 430 ms
61,780 KB
testcase_22 AC 406 ms
61,704 KB
testcase_23 AC 443 ms
61,836 KB
testcase_24 AC 52 ms
36,620 KB
testcase_25 AC 51 ms
37,108 KB
testcase_26 AC 51 ms
37,084 KB
testcase_27 AC 50 ms
36,924 KB
testcase_28 AC 51 ms
36,876 KB
testcase_29 AC 50 ms
36,964 KB
testcase_30 AC 52 ms
37,096 KB
testcase_31 AC 52 ms
37,092 KB
testcase_32 AC 50 ms
37,108 KB
testcase_33 AC 54 ms
36,948 KB
testcase_34 AC 421 ms
59,892 KB
testcase_35 AC 198 ms
47,040 KB
testcase_36 AC 347 ms
58,440 KB
testcase_37 AC 336 ms
56,760 KB
testcase_38 AC 253 ms
50,420 KB
testcase_39 AC 201 ms
46,560 KB
testcase_40 AC 232 ms
45,908 KB
testcase_41 AC 179 ms
46,036 KB
testcase_42 AC 295 ms
54,240 KB
testcase_43 AC 339 ms
58,052 KB
testcase_44 AC 612 ms
61,412 KB
testcase_45 AC 937 ms
61,564 KB
権限があれば一括ダウンロードができます

ソースコード

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) {
					cnt++;
					x /= p;
				}
			}
			ans = Math.min(ans, cnt);
		}
		if (ans == Integer.MAX_VALUE) {
			ans = -1;
		}
		System.out.println(ans);
	}
}
0