Cod sursa(job #3157710)

Utilizator LucaMuresanMuresan Luca Valentin LucaMuresan Data 16 octombrie 2023 18:32:06
Problema Indep Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.27 kb
#include <bits/stdc++.h>
#warning That's the baby, that's not my baby

typedef long long ll;

using namespace std;

const int NMAX = 500;
const int VMAX = 1e3;

struct baban {
    vector<int> v;
    const static int base = 1e9;
    baban () {}
    baban (int x) {
        v.clear();
        while (x) {
            v.push_back(x % base);
            x /= base;
        }
    }
    void normalize () {
        for (int i = 0; i < (int) v.size(); i++) {
            if (v[i] >= base) {
                if (i == (int) v.size() - 1) {
                    v.push_back(0);
                }
                v[i + 1] += v[i] / base;
                v[i] %= base;
            } else if (v[i] < 0) {
                v[i] += base;
                v[i + 1]--;
            }
        }
        while ((int) v.size() > 1 && v.back() == 0) {
            v.pop_back();
        }
    }
    baban operator + (const baban &other) {
        baban res;
        for (int i = 0; i < (int) max(other.v.size(), v.size()); i++) {
            int t = 0;
            if (i < (int) v.size()) {
                t += v[i];
            }
            if (i < (int) other.v.size()) {
                t += other.v[i];
            }
            res.v.push_back(t);
        }
        res.normalize();
        return res;
    }
    void operator += (const baban &other) {
        *this = *this + other;
    }
    friend ostream& operator << (ostream &output, const baban &v) {
        output << (v.v.empty() ? 0 : v.v.back());
        for (int i = (int) v.v.size() - 2; i >= 0; i--) {
            output << setw(9) << setfill('0') << v.v[i];
        }
        return output;
    }

};

baban dp[VMAX + 1], newDp[VMAX + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

#ifndef LOCAL
    freopen("indep.in", "r", stdin);
    freopen("indep.out", "w", stdout);
#endif

    int n;
    cin >> n;

    dp[0] = 1;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        for (int j = 0; j <= VMAX; j++) {
            newDp[j] = dp[j];
        }
        for (int j = 0; j <= VMAX; j++) {
            newDp[__gcd(j, x)] += dp[j];
        }
        swap(dp, newDp);
    }

    cout << dp[1];

    return 0;
}