Cod sursa(job #3367932)

Utilizator RosaSofian Rosa Rosa Data 12 octombrie 2026 13:14:48
Problema Indep Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <fstream>
#include <algorithm>
//#define int long long
using namespace std;

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

using ll= long long;
const int dim= 1e3+ 5;
const int mod= 666013;
int dp[dim][dim];

void add(int a, int b){
    //cout << a<<"+"<< b<< endl;

    //if(a== 1 and b==3)cout <<"da"<< endl;
    int n= dp[a][0];
    int m= dp[b][0];
    int r= 0;
    dp[a][0]= max(dp[a][0], dp[b][0]);
    for(int i= 1;i <= max(n, m);i++){
        int nr= dp[a][i]+ dp[b][i]+ r;
        dp[a][i]= nr% 10;
        r= nr/ 10;
    }

    if(r > 0){
        dp[a][n+ 1]= r;
        dp[a][0]++;
    }

//    if(a== 1 and b== 3){
//        for(int i= 1;i <= dp[a][0];i++)
//            cout << dp[a][i]<<" ";
//        cout <<"//////////////////"<< endl;
//    }
}

int main()
{
    int i, j, n, x;
    cin >> n;

    for(i= 1;i <= n;i++){
        cin >> x;

        for(j= 1;j <= dim;j++){
            int nr= __gcd(j, x);
            add(nr, j);
        }
        dp[x][1]++;
        j= 1;
        while(dp[x][j]== 10){
            dp[x][j]%= 10;
            dp[x][j+ 1]++;
            j++;
        }
        if(j > dp[x][0])dp[x][0]++;

//        for(int k= 1;k <= 15;k++){
//            cout <<"--> ";
//            for(j= 1;j <= dp[k][0];j++)
//                cout << dp[k][j]<<" ";
//            cout << endl;
//        }
//        cout << endl;
    }

    for(j= dp[1][0];j >= 1;j--)
        cout << dp[1][j];

    return 0;
}