結果

問題 No.917 Make One With GCD
ユーザー imoni_kawaii
提出日時 2020-06-18 00:04:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,329 bytes
コンパイル時間 2,523 ms
コンパイル使用メモリ 208,612 KB
最終ジャッジ日時 2025-01-11 05:03:34
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long; using ld = long double; using pll = pair<ll, ll>;
const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

vector<ll> divisor(ll n) {
  vector<ll> divs;
  for (ll i=1; i*i<=n; ++i) {
    if (n%i == 0) {
      divs.push_back(i);
      if (n/i != i) divs.push_back(n/i);
    }
  }
  return divs;
}


ll dp[60][500000];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  set<ll> divs;
  rep(i, n) {
    auto d = divisor(a[i]);
    for(auto e : d) divs.insert(e);
  }
  vector<ll> G;
  G.push_back(0);
  for(auto e : divs) {
    G.push_back(e);
  }
  int m = G.size();
  map<ll, int> idx;
  rep(i, m) idx[G[i]] = i;
  dp[0][0] = 1;
  rep(i, n) rep(j, m) {
    dp[i+1][j] += dp[i][j];
    dp[i+1][idx[gcd(G[j], a[i])]] += dp[i][j];
  }
  cout << dp[n][1] << '\n';
  return 0;
}
0