Cod sursa(job #827372)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 1 decembrie 2012 23:37:04
Problema Indep Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.73 kb
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const int MaxN = 505;
const int MaxV = 1005;
const int Base = 1000000000;
const int MaxC = 50;

class Huge {
public:

	int n[MaxC];

	Huge () { memset(n, 0, sizeof(n)); }

	Huge(int A) { *this = A; }

    Huge operator= (Huge A) {
        memcpy(n, A.n, sizeof(A.n));
        return *this;
    }

	Huge operator= (int A) {
		memset(n, 0, sizeof(n));
		for (; A > 0; A /= Base)
            n[++n[0]] = A % Base;
        return *this;
	}

	Huge operator+ (Huge A) const {
		Huge B; int i, T = 0;
		for (i = 1; i <= A.n[0] || i <= n[0] || T; ++i, T /= Base)
			B.n[i] = (T += (A.n[i] + n[i])) % Base;
		B.n[0] = i - 1;
		return B;
	}

	Huge operator+= (Huge A) {
	    return *this = *this + A;
	}

	void Print() const {
        printf("%d", n[n[0]]);
        for (int i = n[0] - 1; i > 0; --i)
            printf("%.9d", n[i]);
        printf("\n");
	}
};

int N, Value[MaxN], MaxValue;
Huge 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]] += Huge(1);
    }
}

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);
    DP[1].Print();
}

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