Pagini recente » Cod sursa (job #764087) | Cod sursa (job #1648097) | Cod sursa (job #468844) | Cod sursa (job #916599) | Cod sursa (job #2337656)
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1e9;
const int MAXVAL = 1000;
const int MAXN = 1e4;
struct Huge {
int nrcif;
int v[MAXN + 1];
Huge () {
nrcif = 1;
memset (v, 0, sizeof (v));
}
Huge operator = (const Huge &other) {
int i;
nrcif = other.nrcif;
for (i = 1; i <= nrcif; i++)
v[i] = other.v[i];
return *this;
}
Huge operator += (const Huge &other) {
int r, i;
nrcif = max (nrcif, other.nrcif);
r = 0;
for (i = 1; i <= nrcif; i++) {
v[i] = v[i] + r + other.v[i];
r = v[i] / BASE;
v[i] = v[i] % BASE;
}
if (r) {
nrcif++;
v[nrcif] = r;
}
return *this;
}
void afis () {
int i, p;
printf ("%d", v[nrcif]);
for (i = nrcif - 1; i > 0; i--) {
p = BASE / 10;
while (p > v[i]) {
p = p / 10;
printf ("0");
}
printf ("%d", v[i]);
}
printf ("\n");
}
};
Huge dp[MAXVAL + 1];
int cmmdc (int a, int b) {
while (b > 0) {
int r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
int n, i, j, x;
freopen ("indep.in", "r", stdin);
freopen ("indep.out", "w", stdout);
scanf ("%d", &n);
Huge doarunu;
doarunu.nrcif = doarunu.v[1] = 1;
for (i = 1; i <= n; i++) {
scanf ("%d", &x);
for (j = 1; j <= MAXVAL; j++)
dp[cmmdc (x, j)] += dp[j];
dp[x] += doarunu;
}
dp[1].afis ();
return 0;
}