Cod sursa(job #2414876)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 25 aprilie 2019 11:10:27
Problema Indep Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.81 kb
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int BASE = 1e9;
const int VMAX = 1005;
const int NMAX = 105;

class Huge
{
    public:
        int v[NMAX];
        Huge(){memset(v,0,sizeof(v));v[0] = 1;}
        Huge operator = (const Huge &other)
        {
            memset(v,0,sizeof(v));
            for(int i = 0 ; i <= other.v[0] ; i++)
                v[i] = other.v[i];
            return *this;
        }
        Huge operator += (const Huge &other)
        {
            v[0] = max(v[0],other.v[0]);
            int aux,tr = 0;
            for(int i = 1 ; i <= v[0] ; i++)
            {
                aux = v[i] + other.v[i] + tr;
                v[i] = aux % BASE;
                tr = aux / BASE;
            }
            if(tr)
                v[++v[0]] = tr;
            return *this;
        }
        void getHuge()
        {
            int p;
            printf("%d",v[v[0]]);
            for(int i = v[0]-1 ; i >= 1 ; i--)
            {
                p = BASE/10;
                while(p > v[i])
                {
                    p /= 10;
                    printf("0");
                }
                printf("%d",v[i]);
            }
            printf("\n");
        }
};


int cmmdc(int a,int b)
{
    int r;
    while(b)
    {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

Huge dp[VMAX+1];

int main()
{
    freopen("indep.in","r",stdin);
    freopen("indep.out","w",stdout);
    int n,x;
    scanf("%d",&n);
    Huge unu;
    unu.v[0] = unu.v[1] = 1;
    for(int i = 1 ; i <= n ; i++)
    {
        scanf("%d",&x);
        for(int j = 1 ; j <= VMAX-5 ; j++)
            dp[cmmdc(j,x)] += dp[j];
        dp[x] += unu;
    }
    dp[1].getHuge();
    return 0;
}