Cod sursa(job #2648498)

Utilizator OvidRata Ovidiu Ovid Data 11 septembrie 2020 11:16:44
Problema Indep Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.44 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll


ifstream fin("indep.in"); ofstream fout("indep.out");
#define cin fin
#define cout fout

int gcd(int a, int b){
int x=a, y=b;
while(y>0){
    int t=y; y=x%y; x=t;
}
return x;
}


int t, n, m, k, a[501], q, l, r;
vector<int> cnt[501][1001];

vector<int> add(vector<int> a, vector<int> b){
int x=0;
vector<int> res;
for(int i=0; (i<a.size()) || (i<b.size()) ; i++){
    if(i<a.size()){
        if(i<b.size()){
        res.pb(x%10+a[i]+b[i]); x/=10; x+=res.back()/10;
        }else{
        res.pb(x%10+a[i]); x/=10; x+=res.back()/10;
        }
    }
    else{
        if(i<b.size()){
        res.pb(x%10+b[i]); x/=10; x+=res.back()/10;
        }else{
        break;
        }
    }
}
while(x>0){
    res.pb(x%10); x/=10;
}
return res;
}



int32_t main(){
INIT
cin>>n;cnt[0][0]={1};
for(int i=1; i<=n; i++){cin>>a[i]; for(int j=0; j<=1000; j++){cnt[i][j]=add(cnt[i-1][j], cnt[i][j]);int g=gcd(a[i], j);cnt[i][g]=add(cnt[i-1][j], cnt[i][g]);}    }
for(int i=((int)cnt[n][1].size()-1); i>=0; i--){
    cout<<cnt[n][1][i];
}

return 0;
}