結果

問題 No.2811 Calculation Within Sequence
ユーザー Tatsu_mr
提出日時 2024-08-04 23:49:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 195,224 KB
最終ジャッジ日時 2025-02-23 21:01:35
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long x, long long y) {
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

long long gcd_array(vector<long long> a) {
    long long ans = a[0];
    for (int i = 0; i < (int)a.size(); i++) {
        ans = gcd(ans, a[i]);
    }
    return ans;
}

int main() {
    int a, b;
    cin >> a >> b;
    vector<long long> t(a), s(b);
    for (int i = 0; i < a; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> s[i];
    }
    long long g = gcd_array(t);
    for (auto x : s) {
        if (x % g != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
0