Cod sursa(job #1087884)

Utilizator deneoAdrian Craciun deneo Data 19 ianuarie 2014 22:30:04
Problema Indep Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("indep.in");
ofstream fout("indep.out");

const int MAXN = 505;

int n, sir[MAXN];
long long dp[MAXN][MAXN];

int cmmdc(int a, int b) {
    if (!b)
        return a;
    return cmmdc(b, a % b);
}

int main() {
    fin >> n;

    for (int i = 1; i <= n; ++i)
        fin >> sir[i];

    for (int i = 1; i <= n; ++i)
        dp[i][sir[i]] = 1;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (dp[i - 1][j] == 0) continue;

            dp[i][j] += dp[i - 1][j];
            dp[i][cmmdc(j, sir[i])] += dp[i - 1][j];
        }
    }

    fout << dp[n][1] << "\n";
    return 0;
}