結果

問題 No.1250 汝は倍数なりや?
ユーザー tnakao0123
提出日時 2020-10-09 23:06:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 51 ms / 1,000 ms
コード長 948 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 95,008 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 13:58:32
合計ジャッジ時間 2,564 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1250.cc:  No.1250 汝は倍数なりや? - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* 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;
}

/* main */

int main() {
  int n, h;
  scanf("%d%d", &n, &h);

  for (int i = 0; h > 1 && i < n; i++) {
    int ai;
    scanf("%d", &ai);

    if (ai == 0) h = 1;
    else {
      int g = gcd<int>(h, abs(ai));
      h /= g;
    }
  }

  if (h == 1) puts("YES");
  else puts("NO");
  return 0;
}
0