結果

問題 No.2811 Calculation Within Sequence
コンテスト
ユーザー tnakao0123
提出日時 2024-07-22 17:19:09
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 830 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 157 ms
コンパイル使用メモリ 52,888 KB
実行使用メモリ 9,272 KB
最終ジャッジ日時 2026-07-05 08:12:45
合計ジャッジ時間 3,562 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2811.cc:  No.2811 Calculation Within Sequence - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int ts[MAX_N], ss[MAX_N];

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m >= 0, n >= 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

int gcdv(int n, int as[]) {
  int g = 0;
  for (int i = 0; i < n; i++) g = gcd(g, as[i]);
  return g;
}

/* main */

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 0; i < a; i++) scanf("%d", ts + i);
  for (int i = 0; i < b; i++) scanf("%d", ss + i);

  int tg = gcdv(a, ts);
  int sg = gcdv(b, ss);

  if (sg % tg == 0) puts("Yes");
  else puts("No");
  
  return 0;
}
0