Cod sursa(job #3286333)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 14 martie 2025 00:06:11
Problema Indep Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

const int VMAX = 1010, BAZA = 10;

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

void adunare(vector<int>& A, vector<int>& B)
{
    int T = 0;
    auto b = B.begin();
    for(auto a = A.begin(); a != A.end(); ++a)
    {
        if(b == B.end()) T += *a;
        else T += *a + *(b++);
        *a = T % BAZA;
        T /= BAZA;
    }
    while(b != B.end())
    {
        T += *(b++);
        A.push_back(T % BAZA);
        T /= BAZA;
    }
    while(T) A.push_back(T % BAZA), T /= BAZA;
}

void afisare(vector<int>& A)
{
    for(int i = A.size() - 1; i >= 0; --i) fout << A[i];
}

vector<int> dp[VMAX];

int main()
{
    int n, x;
    fin >> n;
    dp[0].push_back(1);
    while(n--)
    {
        fin >> x;
        for(int y = 1; y <= 1000; ++y) adunare(dp[__gcd(x, y)], dp[y]);
        adunare(dp[x], dp[0]);
    }
    afisare(dp[1]);
    return 0;
}