結果

問題 No.917 Make One With GCD
ユーザー Rubikun
提出日時 2019-10-25 22:20:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 679 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 173,860 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 04:24:23
合計ジャッジ時間 2,987 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 15 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a;
        a=a*a;
        b/=2;
    }
    return ans;
}

int main(){

    int N;cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(all(A));
    
    ll ans=0;
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(gcd(A[i],A[j])==1) ans+=rui(2,N-1-j);
        }
        if(A[i]==1) ans++;
    }
    
    cout<<ans<<endl;
}

0