Cod sursa(job #2690171)

Utilizator PredescuSebastianIonPredescu Sebastian Ion PredescuSebastianIon Data 23 decembrie 2020 12:37:28
Problema Indep Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("indep.in");
ofstream g("indep.out");
const int nmax=605,baza=1000;
int n,dp[nmax][105],v[3],x;
void adun(int a[105],int b[105])
{
    int i,r=0;
    for(i=1; i<=a[0] or i<=b[0] or r>0; i++)
    {
        a[i]=a[i]+b[i]+r;
        r=a[i]/baza;
        a[i]%=baza;
    }
    a[0]=i-1;
}
int cmmdc(int a,int b)
{
    int c;
    while(b)
    {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
int main()
{
    f>>n;
    v[0]=v[1]=1;
    for(int i=1; i<=n; i++)
    {
        f>>x;
        for(int j=1; j<=1000; j++)
        {
            adun(dp[cmmdc(x,j)],dp[j]);
        }
        adun(dp[x],v);
    }
    g<<dp[1][dp[1][0]];
    for(int i=dp[1][0]-1; i>=1; i--)
    {
        if(dp[1][i]<10)g<<"00";
        else if(dp[1][i]<100)g<<"0";
        g<<dp[1][i];
    }
    return 0;
}