結果

問題 No.1250 汝は倍数なりや?
ユーザー Strorkis
提出日時 2020-10-09 21:31:16
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 48 ms / 1,000 ms
コード長 905 bytes
コンパイル時間 13,539 ms
コンパイル使用メモリ 383,920 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 08:52:50
合計ジャッジ時間 14,210 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

macro_rules! read_to_tuple {
    ( $( $t:ty ),* ) => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        let mut iter = input.split_whitespace();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}

fn read_line_to_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let iter = input.split_whitespace();
    iter.map(|x| x.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let (n, mut h) = read_to_tuple!(usize, i64);
    let a = read_line_to_vec::<i64>();

    let gcd = |mut a, mut b| {
        let mut r = a % b;
        while r != 0 {
            a = b;
            b = r;
            r = a % b;
        }
        b
    };

    for i in 0..n {
        h /= gcd(a[i], h);
    }
    println!("{}", if h == 1 { "YES" } else { "NO" });
}
0