Cod sursa(job #1847850)

Utilizator preda.andreiPreda Andrei preda.andrei Data 15 ianuarie 2017 10:11:48
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <vector>

#include <iostream>

using namespace std;

const int kMaxVal = 1000;

int Cmmdc(int a, int b)
{
    while (b != 0) {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

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

    int n;
    fin >> n;

    vector<int> d[2];
    d[0].resize(kMaxVal, 0);
    d[1].resize(kMaxVal, 0);

    for (int i = 0; i < n; ++i) {
        int ind = i % 2;
        int last = 1 - ind;

        int val;
        fin >> val;

        d[ind][val - 1] = 1;
        for (int j = 1; j <= kMaxVal; ++j) {
            if (d[last][j - 1] != 0) {
                d[ind][j - 1] += d[last][j - 1];
                d[ind][Cmmdc(j, val) - 1] += d[last][j - 1];
            }
        }

        for (int &x : d[last]) {
            x = 0;
        }
    }

    fout << d[1 - n % 2][0] << "\n";
    return 0;
}