Cod sursa(job #628006)

Utilizator zloteanu.adrianzloteanu adrian nichita zloteanu.adrian Data 31 octombrie 2011 12:16:11
Problema Indep Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
using namespace std;
ifstream q("indep.in");
ofstream w("indep.out");
void suma(int A[], int B[])
{
    int i, t = 0;
    if (!A[0] && !B[0])
    {
        return ;
    }
    for (i=1; i<=A[0] || i<=B[0] || t; i++, t/=10)
    {
        A[i] = (t += A[i] + B[i]) % 10;
    }
    A[0] = i - 1;
}
int cmmdc(int x,int y,int rest)
{
    while(y!=0)
    {
        rest=x%y;
        x=y;
        y=rest;
    }
    return x;
}
int main()
{
    int n,i,j,t,aux[2],v[501],a[1002][501];
    aux[0]=aux[1]=1;
    q>>n;
    for (i=1; i<=n; i++)
    {
        q>>v[i];
    }
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=1000; j++)
        {
            t=cmmdc(v[i],j,0);
            suma(a[t],a[j]);
        }
        suma(a[v[i]],aux);
    }
    for(i=a[1][0]; i>=1; i--)
    {
        w<<a[1][i];
    }
    return 0;
}