Cod sursa(job #1233681)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 25 septembrie 2014 20:55:52
Problema Indep Scor 25
Compilator c Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <stdio.h>
#define VALMAX 1000
long long d[VALMAX+1];
int cmmdc(int a, int b){
    int r;
    while(b!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int main(){
    int n, i, x, j;
    FILE *fin, *fout;
    fin=fopen("indep.in", "r");
    fout=fopen("indep.out", "w");
    fscanf(fin, "%d", &n);
    for(i=0; i<n; i++){
        fscanf(fin, "%d", &x);
        for(j=1; j<=VALMAX; j++){
            d[cmmdc(x, j)]+=d[j];
        }
        d[x]++;
    }
    fprintf(fout, "%lld\n", d[1]);
    fclose(fin);
    fclose(fout);
    return 0;
}