結果

問題 No.2811 Calculation Within Sequence
ユーザー sakikuroe
提出日時 2024-07-19 21:56:19
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,399 bytes
コンパイル時間 23,169 ms
コンパイル使用メモリ 378,288 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-07-19 21:56:49
合計ジャッジ時間 17,171 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

use anmitsu::number_theory::gcd;
use proconio::{fastout, input};

pub mod anmitsu {
    pub mod number_theory {
        /// Returns:
        ///     gcd(a, b)
        ///
        /// Note:
        ///     gcd(0, 0) = 0
        ///     gcd(a, 0) = a
        ///     gcd(a, b) >= 0
        ///     gcd(a, a) == abs(a)
        ///     gcd(a, b) == gcd(b, a)
        ///
        /// Complexity:
        ///     O(log(min(abs(a), abs(b))))
        ///
        /// Exsamples:
        /// ```
        /// use anmitsu::math::number_theory::gcd;
        /// assert_eq!(gcd(0, 0), 0);
        /// assert_eq!(gcd(0, 1), 1);
        /// assert_eq!(gcd(4, 6), 2);
        /// assert_eq!(gcd(4, -6), 2);
        /// assert_eq!(gcd(-4, 6), 2);
        /// assert_eq!(gcd(-4, -6), 2);
        /// assert_eq!(gcd(2, 2), 2);
        /// assert_eq!(gcd(-2, -2), 2);
        /// ```
        pub fn gcd(mut a: i64, mut b: i64) -> u64 {
            while b != 0 {
                (a, b) = (b, a % b);
            }
            a.unsigned_abs()
        }
    }
}

#[fastout]
fn main() {
    input! {
        a: usize, b: usize,
        t: [usize; a],
        s: [usize; b],
    }

    let mut g = t[0];
    for i in 1..a {
        g = gcd(g as i64, t[i] as i64) as usize;
    }

    if (0..a).any(|i| t[i].abs_diff(*s.get(i).unwrap_or(&0)) % g != 0) {
        println!("No");
    } else {
        println!("Yes");
    }
}
0