Cod sursa(job #496910)

Utilizator andra23Laura Draghici andra23 Data 31 octombrie 2010 13:31:33
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include<fstream>
#define nmax 505
#define imax 1005

using namespace std;

int a[nmax], c1[imax], c2[imax];

int cmmdc(int a, int b){
    int r = a%b;
    while (r != 0){
        a = b;
        b = r;
        r = a%b;    
    }    
    return b;
}

int main(){
    ifstream f("indep.in");
    ofstream g("indep.out");
    int n;
    f >> n;
    
    int i, j, k;
    int max = 0;
    for (i = 1; i <= n; i++){
        f >> a[i];
        if (a[i] > max)
            max = a[i];
    } 
    
    c1[a[1]] = 1;
    c2[a[1]] = 1;
    
    for (i = 2; i <= n; i++){
        c2[a[i]]++;
        for (j = 1; j <= max; j++){
            k = cmmdc(a[i], j);
            c2[k] = c2[k] + c1[j];            
        }
        for (j = 1; j <= max; j++){
            c1[j] = c2[j];    
        }    
    }
    
    g << c2[1] << '\n';
    
    return 0;
}