Cod sursa(job #2580452)

Utilizator DavvDrgDavid Dragostin DavvDrg Data 13 martie 2020 17:21:42
Problema Indep Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("indep.in");
ofstream out("indep.out");
long long a[1005];
int gcd(int a,int b)
{
    if(!a || !b)
        return a+b;
    if(a>b)
        return gcd(a%b,b);
    return gcd(a,b%a);
}
int main()
{
    int i,n,x;
    in>>n;
    while(n--)
    {
        in>>x;
        for(i=1; i<=1000; ++i)
            if(a[i])
                a[gcd(x,i)]+=a[i];
        ++a[x];
    }
    out<<a[1];
    return 0;
}