Cod sursa(job #827365)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 1 decembrie 2012 23:30:38
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <cstdio>
#include <algorithm>

using namespace std;

const int MaxN = 505;
const int MaxV = 1005;

int N, Value[MaxN], MaxValue, DP[MaxV];

inline int GCD(int x, int y) {
    while (y != 0) {
        int r = x % y;
        x = y; y = r;
    }
    return x;
}

void Solve() {
    for (int i = 1; i <= N; ++i) {
        for (int PrevValue = 1; PrevValue <= MaxValue; ++PrevValue)
            DP[GCD(Value[i], PrevValue)] += DP[PrevValue];
        ++DP[Value[i]];
    }
}

void Read() {
    freopen("indep.in", "r", stdin);
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i) {
        scanf("%d", &Value[i]);
        MaxValue = max(MaxValue, Value[i]);
    }
}

void Print() {
    freopen("indep.out", "w", stdout);
    printf("%d\n", DP[1]);
}

int main() {
    Read();
    Solve();
    Print();
    return 0;
}