Pagini recente » Cod sursa (job #1682948) | Cod sursa (job #2406052) | Cod sursa (job #787574) | Cod sursa (job #109219) | Cod sursa (job #991079)
Cod sursa(job #991079)
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("indep.in");
const int MAX_N = 510;
const int MAX_V = 1010;
const int MAX_D = 100;
const int base = 1000000000;
int n;
int v[MAX_N];
int dp[2][MAX_V][MAX_D];
inline int cmmdc(const int &a, const int &b) {
if (!b) return a;
return cmmdc(b, a % b);
}
inline void add(int a[], int b[]) {
int i, t = 0;
for (i = 1; i <= a[0] || i <= b[0] || t; ++i, t /= base)
a[i] = (t += a[i] + b[i]) % base;
a[0] = i - 1;
}
int main() {
fin >> n;
freopen("indep.out", "w", stdout);
for (int i = 1; i <= n; ++i)
fin >> v[i];
// dp[i][j] = k; max k elements from first i elements, cmmdc = j;
dp[1][v[1]][0] = dp[1][v[1]][1] = 1;
for (int i = 2; i <= n; ++i) {
int line = i & 1;
dp[line][v[i]][0] = dp[line][v[i]][1] = 1;
for (int j = 1; j < MAX_V; ++j) {
add(dp[line][j], dp[!line][j]);
}
for (int j = 1; j < MAX_V; ++j) {
int c = cmmdc(j, v[i]);
add(dp[line][c], dp[!line][j]);
}
memset(dp[!line], 0, sizeof(dp[!line]));
}
if (dp[n & 1][1][0] == 0)
printf("0");
else
printf("%i", dp[n & 1][1][dp[n & 1][1][0]]);
for (int i = dp[n & 1][1][0] - 1; i >= 1; --i)
printf("%.9i", dp[n & 1][1][i]);
fin.close();
}