Cod sursa(job #2123100)

Utilizator giotoPopescu Ioan gioto Data 5 februarie 2018 19:58:18
Problema Indep Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <cstdio>
using namespace std;

int n;
long long d[505][1005];
inline int cmmdc(int x, int y){
    while(y > 0){
        int r = x % y;
        x = y; y = r;
    }
    return x;
}
int main()
{
    freopen("indep.in", "r", stdin);
    freopen("indep.out", "w", stdout);
    scanf("%d", &n);
    int x;
    scanf("%d", &x);
    d[1][x] = 1;
    for(int i = 2; i <= n ; ++i){
        scanf("%d", &x);
        d[i][x] = 1;
        for(int j = 1; j <= 1000 ; ++j)
            d[i][cmmdc(x, j)] += d[i - 1][j];
        for(int j = 1; j <= 1000 ; ++j)
            d[i][j] += d[i - 1][j];
    }
    printf("%lld", d[n][1]);
    return 0;
}