Cod sursa(job #2710667)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 22 februarie 2021 20:35:12
Problema Indep Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <bits/stdc++.h>

using namespace std;

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

const int base = 1e9;
int N, dp[2][1001][1001], ind = 1;

void add(int A[], int B[]) {
    int i, t = 0;
    for(i = 1; i <= A[0] || i <= B[0] || t; ++i, t /= base)
        A[i] = (t += A[i] + B[i]) % base;
    A[0] = i - 1;
}

int nr_cifre(int x) {
    if(x < 10)
        return 1;
    return nr_cifre(x / 10) + 1;
}

int main() {
    fin >> N;
    for(int i = 0; i < 2; ++i)
        for(int j = 0; j < 1001; ++j)
            dp[i][j][0] = 1;
    dp[0][0][1] = 1;
    for(int i = 1; i <= N; ++i, ind ^= 1) {
        int x;
        fin >> x;
        for(int j = 0; j < 1001; ++j)
            for(int k = dp[!ind][j][0]; k >= 0; --k)
                dp[ind][j][k] = dp[!ind][j][k];
        for(int j = 0; j < 1001; ++j)
            add(dp[ind][__gcd(j, x)], dp[!ind][j]);
    }
    fout << dp[!ind][1][dp[!ind][1][0]];
    for(int i = dp[!ind][1][0] - 1; i > 0; --i) {
        int nr = nr_cifre(dp[!ind][1][i]);
        for(int j = 1; j < 10 - nr; ++j)
            fout << '0';
        fout << dp[!ind][1][i];
    }
}