Cod sursa(job #2926408)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 17 octombrie 2022 19:10:15
Problema Indep Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.36 kb
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;

using namespace std;

const int NMAX = 505;
const int GCDMAX = 1005;
/*******************************/
// INPUT / OUTPUT

ifstream f("indep.in");
ofstream g("indep.out");
/*******************************/
/// GLOBAL DECLARATIONS

int N;
int v[NMAX], x[GCDMAX][GCDMAX];
ll dp[NMAX][GCDMAX];
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    f >> N;
    for (int i = 1 ; i <= N ; ++ i)
    {
        f >> v[i];
    }
}
///-------------------------------------
inline void Solution()
{
    for (int i = 1 ; i < GCDMAX ; ++ i)
    {
        for (int j = 1 ; j < GCDMAX ; ++ j)
        {
            x[i][j] = __gcd(i, j);
        }
    }

    dp[1][v[1]] = 1;
    for (int i = 2 ; i <= N ; ++ i)
    {
        for (int gcd = 1 ; gcd < GCDMAX ; ++ gcd)
        {
            dp[i][gcd] += dp[i - 1][gcd];
            dp[i][x[gcd][v[i]]] += dp[i - 1][gcd];
        }
    }
}
///-------------------------------------
inline void Output()
{
    g << dp[N][1];
}
///-------------------------------------
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ReadInput();
    Solution();
    Output();
    return 0;
}