Cod sursa(job #2610835)

Utilizator Rares31100Popa Rares Rares31100 Data 5 mai 2020 19:08:17
Problema Indep Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <bits/stdc++.h>

using namespace std;

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

int n,a[501];
int dp[501][1001];

int cmmdc(int a,int b)
{
    int rest;
    while(b)
    {
        rest=a%b;
        a=b;
        b=rest;
    }

    return a;
}

int main()
{
    in>>n;

    for(int i=1;i<=n;i++)
        in>>a[i];

    dp[1][ a[1] ]=1;

    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=1000;j++)
        {
            dp[i][ cmmdc(j,a[i]) ]+=dp[i-1][j];
            dp[i][j]+=dp[i-1][j];
        }

        dp[i][ a[i] ]++;
    }

    out<<dp[n][1];

    return 0;
}