結果

問題 No.917 Make One With GCD
コンテスト
ユーザー gyouzasushi
提出日時 2019-10-26 02:33:12
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,277 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,920 ms
コンパイル使用メモリ 215,764 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-08 16:21:25
合計ジャッジ時間 3,012 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int gcd (int x,int y) {
    if (x < y) swap(x, y);
    if (y == 0) return x;
    return gcd(x % y, y);
}

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    
    vector<map<int,ll>> dp(n);
    rep(i,n) dp[i][a[i]]=1;
    
    rep(i,n) {
        rep(j,i) {
            for(auto p:dp[j]) {
                dp[i][gcd(p.first,a[i])]+=p.second;
            }
        }
    }
    
    ll ans=0;
    rep(i,n) {
        //for(auto p:dp[i]) cout<<"dp["<<i<<"]["<<p.first<<"]:"<<p.second<<endl;
        ans+=dp[i][1];
    }
    cout<<ans<<endl;
    
}
0