Cod sursa(job #944108)

Utilizator teoionescuIonescu Teodor teoionescu Data 27 aprilie 2013 14:12:28
Problema Indep Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 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]
long long 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;
}