Cod sursa(job #2226183)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 29 iulie 2018 20:29:39
Problema Indep Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.74 kb
#include <fstream>

using namespace std;

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

class big
{
    private :
        short int cif[100];
        short int len;
    public :
        void operator = (const int &other)
        {
            int aux=other;
            len=0;
            while(aux)
            {
                cif[++len]=aux%10;
                aux/=10;
            }
        }
        void operator += (const big &other)
        {
            big ans;
            int i=1,rezid=0,sum;
            for(i=1;i<=len || i<=other.len || rezid>0;i++)
            {
                sum=rezid;
                if(i<=len)
                    sum+=cif[i];
                if(i<=other.len)
                    sum+=other.cif[i];
                ans.cif[i]=sum%10;
                rezid=sum/10;
            }
            ans.len=i-1;
            len=ans.len;
            for(int i=1;i<=len;i++)
                cif[i]=ans.cif[i];
        }
        void afis ()
        {
            for(int i=len;i>=1;i--)
                fout<<cif[i];
        }
};

const int N=500+1;
const int L=1000+1;

big dp[N][L];
int gcd[L][L];

int main()
{
    for(int i=1;i<L;i++)
    {
        gcd[1][i]=gcd[i][1]=1;
        gcd[i][i]=i;
    }
    for(int i=2;i<L;i++)
        for(int j=2;j<i;j++)
            gcd[i][j]=gcd[j][i]=gcd[i-j][j];
    big v1; v1=1;
    int n;
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        int foo;
        fin>>foo;
        for(int j=1;j<L;j++)
            dp[i][j]=dp[i-1][j];
        dp[i][foo]+=v1;
        for(int j=1;j<L;j++)
        {
            dp[i][gcd[j][foo]]+=dp[i-1][j];
        }
    }
    dp[n][1].afis();
    fout<<"\n";
    return 0;
}
/**

**/