結果

問題 No.2811 Calculation Within Sequence
ユーザー tfltkpc
提出日時 2024-06-19 06:12:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 172,968 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-08 12:13:58
合計ジャッジ時間 9,441 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> s(a);
  vector<int> t(b);
  for (int i = 0; i < a; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> t[i];
  }
  sort(s.begin(), s.end());
  if (b == 0) {
    cout << "Yes" << endl;
  }
  else if (a == 0) {
    cout << "No" << endl;
  }
  else {
    int sgcd = s[0];
    for (int i = 1; i < a; i++) {
      sgcd = gcd(s[i], sgcd);
    }
    bool may = 1;
    for (int i = 0; i < b; i++) {
      if (t[i] % sgcd != 0) {
        may = 0;
        break;
      }
    }
    if (may) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}
0