Pagini recente » Cod sursa (job #425569) | Cod sursa (job #917991) | Cod sursa (job #134634) | Cod sursa (job #3204257) | Cod sursa (job #991032)
Cod sursa(job #991032)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("indep.in");
ofstream fout("indep.out");
const int MAX_N = 510;
const int MAX_V = 1010;
int n;
int v[MAX_N];
int dp[MAX_N][MAX_V];
inline int cmmdc(const int &a, const int &b) {
if (!b) return a;
return cmmdc(b, a % b);
}
int main() {
fin >> n;
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]] = 1;
for (int i = 2; i <= n; ++i) {
dp[i][v[i]] = 1;
for (int j = 1; j < MAX_V; ++j) {
dp[i][j] += dp[i - 1][j];
}
for (int j = 1; j < MAX_V; ++j) {
int c = cmmdc(j, v[i]);
dp[i][c] += dp[i - 1][j];
}
}
fout << dp[n][1] << '\n';
fin.close();
fout.close();
}