Pagini recente » Cod sursa (job #995284) | Cod sursa (job #1250648) | Cod sursa (job #929162) | Cod sursa (job #246847) | Cod sursa (job #827373)
Cod sursa(job #827373)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MaxN = 505;
const int MaxV = 1005;
const int Base = 1000000000;
const int MaxC = 25;
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;
}