結果

問題 No.917 Make One With GCD
ユーザー beet
提出日時 2019-10-25 21:38:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 2,545 ms
コンパイル使用メモリ 203,584 KB
最終ジャッジ日時 2025-01-08 01:05:08
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  Int ans=0;
  for(Int l=0;l<n;l++){
    map<Int, Int> dp;
    dp[as[l]]=1;
    for(Int i=l+1;i<n;i++){
      map<Int, Int> nx;
      for(auto p:dp)
        nx[__gcd(p.first,as[i])]+=p.second;

      for(auto p:nx)
        dp[p.first]+=p.second;
    }
    ans+=dp[1];
  }

  cout<<ans<<endl;
  return 0;
}
0