Cod sursa(job #1198892)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 17 iunie 2014 16:21:35
Problema Indep Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin("indep.in");
ofstream fout("indep.out");
unsigned long long DP[1005];
int v[505],N;

int cmmdc(int a,int b)
{
    if(!b)return a;
    return cmmdc(b,a%b);
}

int main()
{
    fin.sync_with_stdio(false);
    fin >> N;
    for(int i = 1; i <= N; ++i)
        fin >> v[i];
    for(int i = 1; i <= N; ++i){
        for(int j = 1; j <= 1000; ++j)
            DP[cmmdc(j,v[i])] += DP[j];
        DP[v[i]] ++;
    }
    fout << DP[1];

    return 0;
}