結果

問題 No.1250 汝は倍数なりや?
ユーザー urawa72
提出日時 2020-11-18 09:43:40
言語 Rust
(1.83.0 + proconio)
結果
RE  
実行時間 -
コード長 1,061 bytes
コンパイル時間 14,883 ms
コンパイル使用メモリ 391,544 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-23 08:52:40
合計ジャッジ時間 14,868 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 1 RE * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::{input, fastout};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        h: usize,
        a: [usize; n]
    }

    let mut map = HashMap::new();
    let mut i = 2;
    let mut m = h;

    while i * i <= m {
        while m % i == 0 {
            m /= i;
            if map.contains_key(&i) {
                let x = map.get_mut(&i).unwrap();
                *x += 1;
            } else {
                map.insert(i, 1);
            }
        }
        i += 1;
    }
    if m > 1 {
        if map.contains_key(&m) {
            let x = map.get_mut(&m).unwrap();
            *x += 1;
        } else {
            map.insert(m, 1);
        }
    }

    for i in 0..n {
        if h == a[i] {
            println!("YES");
            return;
        }
        if map.contains_key(&a[i]) {
            let x = map.get_mut(&a[i]).unwrap();
            *x -= 1;
        }
    }

    for (_, v) in &map {
        if 0 < *v {
            println!("NO");
            return;
        }
    }

    println!("YES");
}
0