Cod sursa(job #1125627)

Utilizator alexalghisiAlghisi Alessandro Paolo alexalghisi Data 26 februarie 2014 18:46:00
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>

#define DN 505
using namespace std;

int dp[DN+DN],v[DN];

/// dp[j] = nr de subsiruri divizibile cu j

inline int cmmdc(int a,int b){

    int c;
    for(;b;){
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}

int main()
{
    int n;
    ifstream f("indep.in");
    ofstream g("indep.out");
    f>>n;

//    for(int j=1;j<=1000;++j)
//        if(v[1]%j == 0)
//            dp[1][j]=1;

    for(int i=1;i<=n;++i){

        int x;
        f>>x;

        for(int j=1;j<=1000;++j)
            dp[ cmmdc(j,x) ] += dp[j];
        dp[x]+=1;
    }
    g<<dp[1];

    return 0;
}