Cod sursa(job #3247663)

Utilizator AndreiNicolaescuEric Paturan AndreiNicolaescu Data 8 octombrie 2024 18:20:03
Problema Indep Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <vector>
#define int long long
using namespace std;
typedef int NrMare[1010];
ifstream cin("indep.in");
ofstream cout("indep.out");
int n, maxi = -1;
vector <int> v;
int gcd(int a, int b)
{
    while (b != 0)
    {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

int dp[501][1001];
int32_t main()
{
    cin >> n;
    v.resize(n+1);
    for(int i=1; i<=n; i++)
    {
        cin >> v[i];
        maxi = max(maxi, v[i]);
    }

    dp[1][v[1]] = 1;
    for(int i=2; i<=n; i++)
    {

        for(int j=1; j<=maxi; j++)
        {
            dp[i][j] += dp[i-1][j];
            dp[i][gcd(v[i], j)] += dp[i-1][j];
        }
        dp[i][v[i]]++;

    }
    cout << dp[n][1];
    /*cout << endl;
    for(int i=1; i<=n; i++,cout << '\n')
        for(int j=1; j<=maxi; j++)
            cout << dp[i][j] << " ";*/

    return 0;
}