結果
問題 |
No.2682 Visible Divisible
|
ユーザー |
![]() |
提出日時 | 2024-03-20 21:36:37 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,294 ms / 2,000 ms |
コード長 | 825 bytes |
コンパイル時間 | 1,843 ms |
コンパイル使用メモリ | 78,104 KB |
実行使用メモリ | 60,712 KB |
最終ジャッジ日時 | 2024-09-30 07:26:32 |
合計ジャッジ時間 | 21,215 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
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(); } }