Cod sursa(job #1753107)

Utilizator Bodo171Bogdan Pop Bodo171 Data 5 septembrie 2016 20:44:11
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <iostream>
#include<fstream>
using namespace std;
const int base=1e9;
const int nmax=1000;
int n,i,x,modes[1005][1005],c,nr,zeros,j,id,unu[3];
int cmmdc(int a,int b)
{
    if(a<b) swap(a,b);
    while(b!=0)
    {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
void add(int A[],int B[])
{
    if(B[0]>A[0]) A[0]=B[0];
    for(id=1;id<=A[0];id++)
    {
        A[id]+=B[id];
        if(A[id]>=base)
        {
            A[id]-=base;
            A[id+1]++;
            if(id+1>A[0]) A[0]++;
        }
    }
}
int main()
{
    ifstream f("indep.in");
    ofstream g("indep.out");
    f>>n;
    unu[0]=1;
    unu[1]=1;
    for(i=1;i<=n;i++)
    {
        f>>x;
        add(modes[x],modes[x]);
        add(modes[x],unu);
        for(j=1;j<=nmax;j++)
        {
            nr=cmmdc(j,x);
            if(j!=x)add(modes[nr],modes[j]);
        }
    }
    for(i=modes[1][0];i>=1;i--)
    {
        if(i!=modes[1][0])
        {
            x=base;
            zeros=0;
            while(x>modes[1][i])
                x/=10,zeros++;
            zeros--;
        }
        for(j=1;j<=zeros;j++) g<<'0';
        g<<modes[1][i];
    }
    if(modes[1][0]==0) g<<'0';
    return 0;
}