Cod sursa(job #2929583)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 26 octombrie 2022 10:47:13
Problema Indep Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.78 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];
short dp[2][GCDMAX][200], ans[200];
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    f >> N;
    for (int i = 1 ; i <= N ; ++ i)
    {
        f >> v[i];
    }
}
///-------------------------------------
void sum(short a[200], short b[200])
{
    int t = 0, i = 1;
    for (i = 1 ; i <= max(a[0], b[0]) || t > 0 ; ++ i)
    {
        t += (a[i] + b[i]);
        a[i] = t % 10;
        t /= 10;
    }
    a[0] = i - 1;
}
///-------------------------------------
inline void Solution()
{
    dp[0][0][0] = dp[0][0][1] = 1;
    int t = 1;
    for (int i = 1 ; i <= N ; ++ i, t ^= 1)
    {
        for (int gcd = 0; gcd < GCDMAX ; ++ gcd)
            memset(dp[t][gcd], 0, sizeof(dp[t][gcd]));

        for (int gcd = 0 ; gcd < GCDMAX ; ++ gcd)
        {
            sum(dp[t][gcd], dp[t ^ 1][gcd]);
            if (dp[t ^ 1][gcd][0] > 0)
                sum(dp[t][__gcd(gcd, v[i])], dp[t ^ 1][gcd]);
        }
    }

    t = N & 1;
    for (int i = 0 ; i < 200 ; ++ i)
        ans[i] = dp[t][1][i];
}
///-------------------------------------
inline void Output()
{
    for (int i = ans[0] ; i > 0 ; -- i) g << ans[i];
}
///-------------------------------------
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ReadInput();
    Solution();
    Output();
    return 0;
}