結果

問題 No.2682 Visible Divisible
ユーザー tentententen
提出日時 2024-03-25 09:55:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 440 ms / 2,000 ms
コード長 1,565 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 78,472 KB
実行使用メモリ 69,016 KB
最終ジャッジ日時 2024-03-25 09:56:02
合計ジャッジ時間 10,407 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 415 ms
68,316 KB
testcase_01 AC 412 ms
68,580 KB
testcase_02 AC 420 ms
68,672 KB
testcase_03 AC 427 ms
68,296 KB
testcase_04 AC 417 ms
68,076 KB
testcase_05 AC 436 ms
68,284 KB
testcase_06 AC 412 ms
68,604 KB
testcase_07 AC 416 ms
68,632 KB
testcase_08 AC 52 ms
53,984 KB
testcase_09 AC 52 ms
53,984 KB
testcase_10 AC 52 ms
53,968 KB
testcase_11 AC 419 ms
68,960 KB
testcase_12 AC 421 ms
68,312 KB
testcase_13 AC 438 ms
68,592 KB
testcase_14 AC 419 ms
69,016 KB
testcase_15 AC 422 ms
68,984 KB
testcase_16 AC 440 ms
68,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long k = sc.nextLong();
        long lca = 1;
        for (int i = 0; i < n; i++) {
            lca = getLCA(lca, getGCD(sc.nextLong(), k));
        }
        System.out.println(lca == k ? "Yes" : "No");
    }
    
    static long getLCA(long x, long y) {
        return x / getGCD(x, y) * y;
    }
    
    static long getGCD(long x, long y) {
        if (y == 0) {
            return x;
        } else {
            return getGCD(y, x % y);
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0