結果

問題 No.2811 Calculation Within Sequence
ユーザー InTheBloom
提出日時 2024-07-19 21:43:26
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 2,871 ms
コンパイル使用メモリ 89,064 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 21:43:36
合計ジャッジ時間 8,962 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

constexpr int iINF = 1'000'000'000;
constexpr ll llINF = 1'000'000'000'000'000'000;

int gcd (int x, int y) {
    while (0 < x) {
        int t = x;
        x = y % x;
        y = t;
    }
    return y;
}

int main () {
    int a, b; cin >> a >> b;
    vector<int> T(a), S(b);
    for (int i = 0; i < a; i++) cin >> T[i];
    for (int i = 0; i < b; i++) cin >> S[i];

    // 全体のgcdをgとして、相手の任意の項がgで割り切れればOK
    int g = 0;
    for (int i = 0; i < a; i++) g = gcd(g, T[i]);

    bool ok = true;
    for (int i = 0; i < b; i++) if (S[i] % g != 0) ok = false;

    string ans = "Yes";
    if (!ok) ans = "No";

    cout << ans << "\n";
}
0