Cod sursa(job #2710820)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 23 februarie 2021 09:36:56
Problema Indep Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>

using namespace std;

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

const int nmax = 505;
long long n, v[nmax], dp[nmax][1005];

int main(){
    fin >> n;
    for (int i = 1; i <= n; ++i){
        fin >> v[i];
    }
    int t = 0;
    dp[1 - t][1] = 1;
    for (int i = n; i >= 1; --i){
        for (int j = 0; j <= 1000; ++j){
            dp[t][j] = 1LL * dp[1 - t][j] + dp[1 - t][__gcd(1LL * j, v[i])];
        }
        t = 1 - t;
    }
    t = 1 - t;
    fout << dp[1][0];
    fin.close();
    fout.close();
    return 0;
}