Cod sursa(job #2952231)

Utilizator rares89_Dumitriu Rares rares89_ Data 8 decembrie 2022 20:07:01
Problema Indep Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>

using namespace std;

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

int n, x;
long long int dp[505][1005];

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

int main() {
    fin >> n;
    for(int i = 1; i <= n; i++) {
        fin >> x;
        for(int j = 1; j <= 1000; j++) {
            int cmmdc = gcd(x, j);
            if(dp[i][cmmdc] == 0) {
                dp[i][cmmdc] = dp[i - 1][cmmdc];
            }
            dp[i][cmmdc] += dp[i - 1][j];
        }
        for(int j = 2; j <= 1000; j++) {
            if(dp[i][j] == 0) {
                dp[i][j] = dp[i - 1][j];
            }
        }
        dp[i][x]++;
    }
    fout << dp[n][1];
    return 0;
}