Cod sursa(job #944107)

Utilizator teoionescuIonescu Teodor teoionescu Data 27 aprilie 2013 14:09:20
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<fstream>
using namespace std;
ifstream in("indep.in");
ofstream out("indep.out");
const int N = 505;
const int L = 1005;
int v[N],d[N][L];
int n;
int cmmdc(int a,int b){
    if(!b) return a;
    else return cmmdc(b,a%b);
}
void af(){
    int i,j;
    for(i=1;i<=n;i++){
        for(j=1;j<=1000;j++){
            out<<d[i][j]<<' ';
        }
        out<<'\n';
    }
}
int main(){
    int i,j;
    in>>n;
    for(i=1;i<=n;i++) in>>v[i];
    for(i=1;i<=n;i++){
        d[i][v[i]]+=1;
        for(j=1;j<=1000;j++){
            d[i][j]+=d[i-1][j];
            d[i][cmmdc(j,v[i])]+=d[i-1][j];
        }
    }
    //af();
    out<<d[n][1];
    return 0;
}