結果

問題 No.1330 Multiply or Divide
ユーザー ks2m
提出日時 2021-01-08 22:17:25
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 2,488 ms
コンパイル使用メモリ 76,832 KB
実行使用メモリ 61,536 KB
最終ジャッジ日時 2024-11-16 12:48:52
合計ジャッジ時間 12,799 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37 WA * 7 RE * 2
権限があれば一括ダウンロードができます

ソースコード

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) {
			throw new Exception();
		}
		System.out.println(ans);
	}
}
0