結果

問題 No.1250 汝は倍数なりや?
ユーザー phsplsphspls
提出日時 2022-11-13 18:09:57
言語 Rust
(1.77.0)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 758 bytes
コンパイル時間 2,728 ms
コンパイル使用メモリ 143,036 KB
実行使用メモリ 5,304 KB
最終ジャッジ日時 2023-10-13 02:28:05
合計ジャッジ時間 4,957 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 1 ms
4,356 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 55 ms
5,304 KB
testcase_34 AC 28 ms
4,352 KB
testcase_35 AC 47 ms
4,784 KB
testcase_36 AC 50 ms
5,172 KB
testcase_37 AC 29 ms
4,376 KB
testcase_38 AC 32 ms
4,352 KB
testcase_39 AC 28 ms
4,352 KB
testcase_40 AC 30 ms
4,348 KB
testcase_41 AC 37 ms
4,352 KB
testcase_42 AC 21 ms
4,352 KB
testcase_43 AC 47 ms
5,060 KB
testcase_44 AC 21 ms
4,504 KB
testcase_45 AC 50 ms
5,100 KB
testcase_46 AC 15 ms
4,376 KB
testcase_47 AC 32 ms
4,376 KB
testcase_48 AC 1 ms
4,356 KB
testcase_49 AC 1 ms
4,352 KB
testcase_50 AC 1 ms
4,348 KB
testcase_51 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
  --> Main.rs:11:9
   |
11 |     let n = nh[0];
   |         ^ help: if this is intentional, prefix it with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn gcd(a: isize, b: isize) -> isize {
    if b == 0 { return a; }
    gcd(b, a%b)
}

fn main() {
    let mut nh = String::new();
    std::io::stdin().read_line(&mut nh).ok();
    let nh: Vec<usize> = nh.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nh[0];
    let h = nh[1] as isize;
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<isize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    if a.iter().filter(|&&v| v == 0).count() > 0 {
        println!("YES");
        return;
    }
    let result = a.iter().map(|&v| gcd(h, v.abs())).fold(1isize, |x, y| gcd(h, x*y));
    if result == h {
        println!("YES");
    } else {
        println!("NO");
    }
}
0