Cod sursa(job #2580655)

Utilizator MatteoalexandruMatteo Verzotti Matteoalexandru Data 13 martie 2020 20:38:32
Problema Indep Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.3 kb
/*
                `-/oo+/-   ``
              .oyhhhhhhyo.`od
             +hhhhyyoooos. h/
            +hhyso++oosy- /s
           .yoooossyyo:``-y`
            ..----.` ``.-/+:.`
                   `````..-::/.
                  `..```.-::///`
                 `-.....--::::/:
                `.......--::////:
               `...`....---:::://:
             `......``..--:::::///:`
            `---.......--:::::////+/`
            ----------::::::/::///++:
            ----:---:::::///////////:`
            .----::::::////////////:-`
            `----::::::::::/::::::::-
             `.-----:::::::::::::::-
               ...----:::::::::/:-`
                 `.---::/+osss+:`
                   ``.:://///-.
*/
#include <fstream>
#include <algorithm>

using namespace std;

const int INF = 2e9;
const int N = 500;
const int MAX = 1000;
const int DIGITS = 100;

int v[5 + N];

ifstream in ("indep.in");
ofstream out ("indep.out");

struct HugeN {
    int v[5 + DIGITS];

    HugeN SetValue(int value) {
        int i;

        for(i = 1; value > 0; i++, value /= 10)
            v[i] = value % 10;

        v[0] = i - 1;
    }

    HugeN operator += (const HugeN B) {
        int i, t(0);

        for(i = 1; i <= v[0] || i <= B.v[0] || t; i++) {
            v[i] = v[i] + B.v[i] + t;
            t = v[i] / 10;
            v[i] = v[i] % 10;
        }

        v[0] = i - 1;
    }

    void Reset() {
        for(int i = v[0]; i >= 0; i--)
            v[i] = 0;
        v[0] = 1;
    }

    void Print() {
        int i = v[0];

        while(i > 0) {
            out << v[i];
            i--;
        }
    }
};
HugeN dp[2][5 + MAX];
HugeN One;

int main() {
    //freopen("indep.in", "r", stdin);
    //freopen("indep.out", "w", stdout);

    int n, lin;
    in >> n;

    for(int i = 1; i <= n; i++)
        in >> v[i];

    One.SetValue(1);
    lin = 0;

    dp[lin][v[1]] += One;
    for(int i = 2; i <= n; i++) {
        lin = 1 - lin;

        for(int j = 1; j <= MAX; j++)
            dp[lin][j].Reset();

        for(int j = 1; j <= MAX; j++) {
            dp[lin][j] += dp[1 - lin][j];
            dp[lin][__gcd(v[i], j)] += dp[1 - lin][j];
        }

        dp[lin][v[i]] += One;
    }

    dp[lin][1].Print();
    return 0;
}