結果

問題 No.917 Make One With GCD
ユーザー どららどらら
提出日時 2019-10-26 01:43:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,394 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 181,428 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 16:42:58
合計ジャッジ時間 3,056 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> divisor(int n){
  vector<int> ret;
  for(int i=1; i*i<=n; i++){
    if(n%i==0){
      ret.push_back(i);
      if(i!=n/i) ret.push_back(n/i);
    }
  }
  //sort(ret.begin(), ret.end());
  return ret;
}

int gcd(int a, int b){return (b==0?a:gcd(b,a%b));}

int main(){
  int N;
  cin >> N;
  vector<ll> v;
  map<int,int> memo;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
    vector<int> div = divisor(a);
    rep(j,div.size()){
      memo[div[j]] = 1;
    }
  }

  map<int,int> inv;
  vector<int> w;
  FOR(it,memo){
    w.push_back(it->first);
    inv[it->first] = w.size()-1;
  }

  vector<vector<ll>> dp(N+1, vector<ll>(w.size(), 0));
  rep(i,N){
    int a = v[i];
    rep(j,w.size()){
      int b = w[j];
      dp[i+1][j] += dp[i][j];
      if(dp[i][j] > 0){
        dp[i+1][inv[gcd(a,b)]] += dp[i][j];
      }
    }
    dp[i+1][inv[a]]++;
  }
  /*
  rep(i,dp.size()){
    rep(j,dp[i].size()){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */

  ll ret = 0;
  REP(i,1,dp[N].size()) ret += dp[N][i];
  
  cout << (1LL<<N)-1-ret << endl;
  
  return 0;
}

0