結果

問題 No.2682 Visible Divisible
ユーザー ks2mks2m
提出日時 2024-03-20 21:36:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,529 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 3,491 ms
コンパイル使用メモリ 77,320 KB
実行使用メモリ 76,084 KB
最終ジャッジ日時 2024-03-20 21:37:06
合計ジャッジ時間 26,591 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,405 ms
75,504 KB
testcase_01 AC 1,367 ms
74,404 KB
testcase_02 AC 1,365 ms
74,848 KB
testcase_03 AC 1,433 ms
74,852 KB
testcase_04 AC 1,434 ms
74,296 KB
testcase_05 AC 1,504 ms
74,312 KB
testcase_06 AC 1,397 ms
76,084 KB
testcase_07 AC 1,338 ms
74,352 KB
testcase_08 AC 137 ms
57,708 KB
testcase_09 AC 133 ms
57,700 KB
testcase_10 AC 138 ms
57,964 KB
testcase_11 AC 1,484 ms
74,472 KB
testcase_12 AC 1,418 ms
74,760 KB
testcase_13 AC 1,365 ms
74,644 KB
testcase_14 AC 1,529 ms
74,692 KB
testcase_15 AC 1,388 ms
74,320 KB
testcase_16 AC 1,492 ms
74,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		sc.close();

		long s = 1;
		for (int i = 0; i < n; i++) {
			long g1 = gcd(s, a[i]);
			a[i] /= g1;
			long g2 = gcd(k, a[i]);
			k /= g2;
			s = lcm(s, g2);
		}
		if (k == 1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	static long lcm(long a, long b) {
		BigInteger ba = BigInteger.valueOf(a);
		BigInteger bb = BigInteger.valueOf(b);
		return ba.multiply(bb).divide(ba.gcd(bb)).longValue();
	}
}
0