Cod sursa(job #1933221)

Utilizator Mihai_PredaPreda Mihai Dragos Mihai_Preda Data 20 martie 2017 16:07:00
Problema Indep Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>

using namespace std;

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

const int valMax = 1000;
const int nMax = 505;
const int base = 10;
const int dim = 505;

struct BigNumber
{
    int lg;
    int c[dim];
    BigNumber(int x = 0)
    {
        lg = 0;
        memset(c, 0, sizeof(c));
        if(x == 0)
            lg++;
        while(x != 0)
        {
            c[lg++] = x % base;
            x /= base;
        }
    }

    void operator +=(const BigNumber &that)
    {
        if(that.lg > lg)
            lg = that.lg;
        int t = 0;
        for(int i = 0; i < lg; ++i)
        {
            if(i < that.lg)
                c[i] += that.c[i];
            c[i] += t;

            t = c[i] / base;
            c[i] %= base;
        }
        if(t)
            c[lg++] = t;
    }
};

int n;
BigNumber dp[valMax+1];
int a[nMax];

void citire()
{
    in >> n;
    for(int i = 1; i <= n; ++i)
        in >> a[i];
}

void rezolvare()
{
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= valMax; ++j)
        {
            dp[__gcd(a[i], j)] += dp[j];
        }
        dp[a[i]] += BigNumber(1);
    }
    for(int i = dp[1].lg - 1; i >= 0; --i)
        out << dp[1].c[i];
}

int main()
{
    citire();
    rezolvare();
    return 0;
}