結果

問題 No.2811 Calculation Within Sequence
ユーザー Tatsu_mrTatsu_mr
提出日時 2024-08-04 23:49:25
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 204,196 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-08-04 23:49:37
合計ジャッジ時間 11,439 ms
ジャッジサーバーID
(参考情報)
judge1 / 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