Cod sursa(job #3314499)

Utilizator postolacheepostolache postolachee Data 10 octombrie 2025 10:40:04
Problema Indep Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <bits/stdc++.h>
//#define int long long
#pragma GCC optimize ("O4,Ofast,unroll-loops")
#define pb push_back
using namespace std;

vector <vector<int>> dp(1001, {0});

void Adunare(vector <int> &a,vector <int> &b){
    while (b.size()>a.size()){
        a.push_back(0);
    }
    while (b.size()<a.size()){
        b.push_back(0);
    }
    int r = 0;
    for (int i=0;i<a.size();++i){
        a[i] = a[i]+b[i]+r;
        r = a[i]/10;
        a[i] = a[i]%10;
    }
    if (r){
        a.push_back(r);
    }
    return;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ifstream cin ("indep.in");
    ofstream cout ("indep.out");
    int n;cin >> n;
    vector <int> v;
    for(int i=0;i < n;i++){
        int x;cin >> x;v.pb(x);
    }
    //dp[v[0]]=1;
    vector<int> unu(1, 1);
    Adunare(dp[v[0]], unu);
    int mx=v[0];
    for(int i=1;i < n;i++){
        for(int j=1;j <= mx;j++){
            Adunare(dp[__gcd(v[i], j)], dp[j]);
        }
        //dp[v[i]]++;
        Adunare(dp[v[i]], unu);
        mx=max(mx, v[i]);
    }
    if(dp[1].size() == 1 && dp[1][0] == 0){
        cout << 0;
        return 0;
    }
    reverse(dp[1].begin(), dp[1].end());
    bool ok = true;
    for(auto x : dp[1]){
        if(x == 0 && ok)continue;
        ok=false;
        cout << x;
    }
    return 0;
}