結果

問題 No.917 Make One With GCD
ユーザー nejinejinejineji
提出日時 2019-10-25 22:40:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,640 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 173,692 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 16:39:36
合計ジャッジ時間 3,132 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
#define PER(i,y,x) for(ll i=y; i>=x; i--)
#define SIZE(v) ll(v.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
typedef long long ll;

void f(ll y, set<ll>& st){
        ll x = y;
        for(int i=1;i*i<=x;i++){
                if(y % i == 0){
                        st.insert(i);
                        st.insert(y/i);
                }
        }
}

int main(){
        ll n;
        cin >> n;
        vll a;
        REP(i,1,n){
                ll x;
                cin >> x;
                a.push_back(x);
        }
        set<ll> st;
        REP(i,0,n-1){
                f(a[i], st);
        }
        vll v;
        for(auto x:st){
                v.push_back(x);
        }
        reverse(v.begin(), v.end());
        vll num(v.size());
        for(int i=0;i<v.size();i++){
                ll x = v[i];
                ll cnt = 0;       
                REP(j,0,n-1){
                        if(a[j] % x == 0){
                                cnt++;
                        }
                }
                ll tmp = pow(2,cnt) - 1;
                num[i] += tmp;
                for(int j=i+1;j < v.size();j++){
                        if(v[i] % v[j] == 0){
                                num[j] -= num[i];
                        }
                }
        }
        ll sum = 0;
        REP(i,0,SIZE(v)-1){
                sum += num[i];
        }
        cout << num[num.size() - 1] << endl;
}
0